Prevent WordPress Plugins From Breaking Your Theme

November 24, 2008 · Print This Article

Have you ever deactivated a WordPress plugin only to find that your WordPress blog no longer works?   This is something that can happen in any situation where a WordPress plugin is called by your WordPress theme without using the proper statement.  

How Can I Avoid This Problem?

Whenever you add plugin functionality to your WordPress theme that uses a call, make sure to turn it into a variable, so your theme won’t break if the plugin is deactivated.  An example would be the popular Related posts plugin that most people use.  In order to use this plugin, you’ll have to insert the following code somewhere into your Revolution theme where you want the related posts to display:

<?php related_posts(); ?>

Instead of using this code, grab the related_posts and convert it to the following code:

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

This way when your page is loading, it will check for the plugin to see if it is activated and use it.  If it isn’t activated, it will ignore the code and your page should load fine!

If you use this method with all of your WordPress plugins you won’t have to worry about accidentally deactivating a plugin and finding a php error on your blog several hours/days later.

Your choice for site templates and wordpress themes


Got something to say?

You must be logged in to post a comment.