How To: Prevent WordPress Plugins From Breaking Your Blog

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.

Source : Hack WordPress


Rate this:
2.5

If you enjoyed this post, make sure you subscribe to my RSS feed!

How To Rewrite Article MoreNiche Style Free Download Camp Funshine: Carrie the Caregiver 3 Game

One comment

  1. no imageCoupons (Who am I?)
    #1

    Thanks for your article, Now there is more reason to comment than ever before! This is a great fir for our project!

    Rate this:
    3.5

Leave a Reply





XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

One Trackback/Ping