Keep your theme safe! Many plugins instruct you to insert something like this into your themes sidebar:
1 | < ? 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:
1 | < ? 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
{ 4 comments… read them below or add one }
Is this in reference to word press or some other blog software? Im guessing WP because this is a WP blog, yes?
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.
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
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.