Don’t Break Theme When Uninstalling a Plugin

Posted in Did you know? on June 6th, 2008

Justin RainsWelcome! Thank you for visiting!
Please Subscribe to my full feed.

Keep your theme safe! Many plugins instruct you to insert something like this into your themes sidebar:


< ? plugin_function_call();?>

The problem with this is that if the plugin is ever deactivated and the web server tries to make that call to the function plugin_function_call it will break and the sidebar will not load correctly or at all. PHP has a great way to get around this. Instead of using the code above use this code:


< ? if (function_exists('plugin_function_call')) plugin_function_call(); ?>

PHPs function_exists checks for a function to be valid. If the function is not valid false is returned and the call after the if statement will not get executed. Now if you decide to remove that plugin for whatever reason you will not need to search through your sidebar code and remove the function call.

This fix will also for for other files in the wordpress theme area. I have added code in index.php, home.php, comments.php and other files and have always used the function_exists code to make sure my


Related Posts:



4 Comments »

  1. Gravatar

    Is this in reference to word press or some other blog software? Im guessing WP because this is a WP blog, yes?

    Comment by Web Hosting Blog — June 11, 2008 @ 3:15 am

  2. Gravatar

    The php function function_exists is not a wordpress specific function but yes I use it mostly in wordpress but it could be used in other php based blogs.

    Comment by Justin — June 11, 2008 @ 8:48 am

  3. Gravatar

    This is a great point. You don’t want visitors coming to your blog and seeing a PHP error, it makes you look unprofessional.

    This is also a good reason why you should have a dev.yourname.com site. You can test activating / deactivating, theme changes, etc. on this site before you go live on your production blog.

    Developer Tutorialss last blog post..Being a Great Developer

    Comment by Developer Tutorials — June 26, 2008 @ 7:57 am

  4. Gravatar

    php errors would be great! Usually if there is an error in say sidebar.php then the sidebar just doesn’t display. I’d like an error like “call to undefined function” that would help alot.

    Comment by Justin — June 26, 2008 @ 8:51 pm


RSS feed for comments on this post. TrackBack URI



Leave a comment




  • I Share

      Share Feed: Subscribe
  • Recent Visitors

  • Blogroll

  • Cool Stuff