Today we’re going to discuss a very useful hack I stumbled upon a month or two ago. I had a client who wanted to see live examples of a WordPress theme she was thinking about purchasing. The official demo looked great, sure; but what did the theme look like in the wild, running on an actual site?

It seemed like a reasonable request, so I thought I’d try a Google search for the theme. The search returned a lot of live sites, so I showed my client a couple of examples, and we ended up going with the theme.

Hey, that shouldn’t work!

It was David (my business partner, more technically astute than I am) who told me that finding theme data through a Google search should be impossible: search engines don’t index CSS files or similar documents, and any PHP scripts that refer to the theme by name would be strictly server-side, processed into HTML long before they could be served to anyone.

So how do you find this information?

How to do it

Here’s how to find live sites for a given WordPress theme:

1. You’ll want to run a very particular Google search. Here’s how it looks:

"wp-content/themes/(theme-name)"

Two notes on this. First, the quotation marks are important: you want results that contain the words in your search in their exact order.

Second, “[theme-name]” above refers to the name of the theme’s folder on an actual WordPress install. So for the Twenty Twelve theme, this would be “twentytwelve”—not “Twenty Twelve”. (As a preliminary hint: if it’s got spaces in it, there’s a good chance that you’re doing it wrong.)

For the Twenty Twelve example, the full search would look like “wp-content/themes/twentytwelve” and would include those quotation marks.

2. Now look for a search result whose description (the black text below the URL) looks like a weird error. That’s what you want.

3. Open the result and see what you find. Sometimes the site you get will be totally nonfunctioning, or one of those “index-of” pages that turns your browser into a weird file system navigator.

If you get one of these, try again with another search result. In about 50% of cases, the result will be a fully functioning site running a configured and customized instance of the theme you’re looking for.

Why it works

Certain kinds of mistakes cause PHP to spit out error messages onto the page as plaintext. Google will sometimes index these messages.

The answer is PHP errors. When web developers make certain kinds of mistakes—coding links improperly, deleting needed theme resources, etc.—this causes PHP to spit out error messages onto the page as plaintext. Google will sometimes index these messages, and store them as part of what it believes to be the page content.

Crucially, these error messages have direct references to the theme being used by the site. PHP errors include the path to the malfunctioning file, and it’s this path that contains the theme name data that the search engines pick up.

So you’re getting an error something like this:

Warning: Invalid argument supplied for foreach() in /home/wplocus/wp-content/themes/room09/core/functions-core.php

And that’s what Google is directing you to.

What you can use it for

With any luck, being able to find live sites running a given theme will give you (or your clients) a vivid, accurate picture of what to expect from the theme or themes you’re considering. It certainly helped our client settle on a theme that ended up being a great fit for her. (Here’s her site, running a child theme of the Room 09 theme depicted above.)

This hack lets you see how themes actually look and function, when developed into sites by real users and third-party developers.

You can also use this hack to sniff out dull themes. Many themes’ official demos look good mainly because of large, beautiful sample images and custom design elements. When your client hands you the theme file and you get rid of these elements (which have nothing to do with the site you’re trying to build), you realize that there’s basically nothing left. I’ve been burned this way more than once. This hack lets you see how themes actually look and function, when developed into sites by real users and third-party developers. It’s a bit like getting to see the way your new haircut will look a week and a half from now.

Finally, maybe you can take this as a tiny example of a message I remember hearing from children’s cartoons and nursery rhymes: Sometimes, when you don’t know something should be impossible, you can actually do it. This probably isn’t the most inspirational thing you’ll read today (if it is—and I’d rarely say this—you should probably spend more time browsing the stuff your friends link to on Facebook), but if the topic comes up at a party you’ll at least have a ready, if humble, example.

Cheers!