Solution – Wordpress Theme Reverts to Default (Kubrick)

OK, as some of you may have noticed if you come here every now and then, this site has been periodically reverting to the big, ugly default theme for Wordpress, known as Kubrick. It has been seemingly doing this all by itself. I thought perhaps it was a bug introduced by the Amazon Media Manager plug-in, so I completely removed it. The site ran fine for a few days and then, all of a sudden, the damn site reverts to Kubrick yet again. So, obviously it wasn’t AMM. I then began to wonder if perhaps Wordpress has a security breach that is allowing somebody to change my theme on me just to annoy me. Problem was that nobody else has reported this as a bug. There are a few other Wordpress users having the same problem, however it is certainly nothing widespread. So, it’s not a security problem either.

So, I investigate. First thing I do is look at the server MySQL query log. The log is called access_log, and each day’s logs are compressed via GZIP and stored in the same directory (/usr/local/var/logs). Now, in my case, the access_log file is WAY too big to open in a local text editor. So, instead, I use the grep command on the command prompt after logging into my server with Putty. I run the following on my access_log (after browsing to the above directory) to do a pattern matching:

grep "UPDATE wp_options" access_log

I get a long printout of all lines of the access log which contain that string. Sure enough, I find two lines, back-to-back, with the following:

UPDATE wp_options SET option_value = 'default' WHERE option_name = 'template'
UPDATE wp_options SET option_value = 'default' WHERE option_name = 'stylesheet'

Well, there’s my culprit. Unfortunately, it doesn’t tell me much. So, I open up Wordpress’s files in my text editor and start searching the code for this query. I find that there is a function called update_option() in the functions.php file which is used to update any option in Wordpress. So, I run another search for a query which would update specifically the “template” option. I find the get_template() function which does this. And, sure enough, if you look at the code, it is designed so that if the theme directory is not found, it will set both the “template” and “stylesheet” to default. That is by design, and not a bug. So, the question is, what is calling up this site’s Wordpress files from another location? If this site’s database was called from another location using a Wordpress installation which did NOT have the same theme installed, it would obviously set me back to “default”.

Well, now I’m onto something, but unfortunately, on first glance, I don’t have anything installed on this server which would be calling the same database using different Wordpress files. But, do I? Here is the “kick my own ass” moment. Yes, I did. I had had a Wordpress installation on this site sitting in the “blog” sub-folder which I used for testing back in the day. Something on that site must have been spidered and somebody came upon it. The moment I went and called up www.webbyonline.com/blog/, my theme on this site reverted to “default”.

So, the simple handle was to find the Wordpress copy which was calling up the same database (in my case in the /blog/ folder) and delete it. I guess I should give this a few days to make sure I really solved it, but I bet this is the problem.

For those few who may also have this problem, there are a few options if, for some reason, you can’t find the source of it:

  • Put the files for your real theme into the “default” theme directory so that if it happens, your site will still look OK
  • Change the code for the get_template() function so that if sets the options to your desired theme rather than default if the theme files cannot be found
  • If you simply CANNOT find the source, you can modify the get_template() function so that it will email you the referrer information in the event that it resets your theme. Something like:

    mail("YOUR EMAIL","Wordpress Debug","Self: ".$_SERVER[REQUEST_URI]."\nDoc Root: ".$_SERVER[DOCUMENT_ROOT]);

    added right below:

    update_option('stylesheet', 'default');

    Then, just monitor your email. If the site resets, you should get an email in your in-box which displays the path to the offending Wordpress installation. If you suspect it could be on a different server, then just include a line to print the IP address, too. Once you take care of it, just go back and remove or comment out the above line of code.

This should help those who have this problem. For the rest of you, sorry about the overly technical post.

If you enjoyed this article, you might also like...

  1. Wordpress Theme Switch – Solved?
  2. Mystery Wordpress Theme Switch Continues…
  3. Wordpress and Curing High Server Load
  4. How To Replace Your Wordpress Search With Google
  5. How To Use a Custom Page Template In Wordpress

Subscribe to blog updates, news and more?
Enter email:

3 Day Money - Making Money Online As a ProBlogger

  • You are a legend, thank you so much.
    I am having the problem you described, and was beginning to wonder if a friend was playing a joke on me. I realised it was a bit too subtle for them, and didn't know where to look next.
    I've recently had to do a dirty install of 2.13, so I'm assuming there are files left over from that causing the issue.
    I'll insert the suggested code and take it from there.
    Thanks again.
  • Scratch that, it turned out I hadn't followed the instructions for the King Mobile plug-in. Many thanks for your guidance...
  • Popularity Contest, WP Mobile Edition, and WP-PostRatings so it could be any of those.

    Thanks again for posting.
  • OK, OK, it took Chris Merriman two comments to figure it out, me too. Was also WP Mobile Edition. Fixed. Thanks again.
  • Thanks for this good post. I came across it while searching for a fix to this problem. Your post made me realize that my particular problem was caused by the WPAU plugin leaving a WP installation in a WPAU-backup folder in the site's root directory.
  • Thank you for posting this article! I was so confused why that would be happening to me! As soon as you suggested another site looking for a theme I remembered that my site had originally be loaded at another location and I had moved early on in it's development.

    Basically speaking, I had two wordpress installs running on the same database. I had forgotten about one and didn't know it was switching the theme on me. Now I know what happened and hopefully it should be fixed for good now!! Praise God :).

    Thank you so much.

    God Bless,
    -Dan
blog comments powered by Disqus