Have you ever deactivated a WordPress plugin only to find that it broke your blog won ‘t load any longer?  This is most common when you have your plugins deactivated because you are upgrading WordPress. 

The reason this is happening is because many WordPress plugin authors provide the call to the plugin without using an “if”.  This causes the call to the plugin to break your page when the server goes to pull the plugin code and discovers it has been deactivated.  

This actually isn’t very difficult to fix, so I figured I would write a quick post explaining how to do so.    I’ll use the popular Related Posts plugin for my example.     Once you’ve downloaded and installed the plugin, you’ll need to place some code where you want the related posts to display.    The plugin author gives you the following code to use:

<?php related_posts(); ?>

As you can see, there is no if/then involved, so it will cause problems if you deactivate the plugin.   Here is how the code needs to look to avoid breaking your blog:

<?php if(function_exists('related_posts')) { related_posts(); } ?>

You just need to take the related_posts in drop it in there twice.   This way if you deactivate the Related Posts plugin, it won’t cause any problems. 

To avoid problems in the future, I recommend going through your plugin list and converting all your plugin calls to the above format.  

Want automatic updates? Subscribe to our RSS feed or
Get Email Updates sent directly to your inbox!
Tweet This | Digg This | Stumble it | Add to Del.icio.us | | Print This

Kyle Eslick

Kyle Eslick is the founder and primary author of WordPress Hacks. You can learn more about him at KyleEslick.com or you can follow his personal tweets here.

There Are 2 Responses So Far »

  1. Rocque says:

    Thanks for this article. Something broke my blog and I thought it was the Exec-php plug in when I upgraded to 2.5.1. One blog worked perfectly and the next blog won’t keep the same template as the “good blog”. The template keeps changing on its own back to the Kubrick template. I am totally lost as to why this is happening.

    Upgrade “good blog” perfect. Upgrade next blog using same procedures and disaster.

    Are there any suggestions?

  2. Mike says:

    Great tip.
    I have deactevted my related posts plugin, but my single.php pages still show related posts.
    There is no call on this page like

    Can someone help me get rid of my related posts?
    Could it be something’s still embedded in the mySQL database that generates the related posts?

    You can view my problem on my photography blog:
    http://mikevisser.nl/blog

Trackbacks/Pingbacks »

Leave a Reply