
For bloggers, nothing is more disheartening than a blank page with one line of an error description calling a PHP function that WordPress doesn’t recognize. This error may be created by many different situations, such as a new plugin or renaming files in your web server, but the end result still breaks your WordPress blog until you fix the problem.
This is why I propose that you start using an excellent feature that PHP has, which is the if (function_exists) statement. By using this simple code when you call an external plugin file within WordPress, you create a failsafe method of preserving your blog when altering files.
This code (quite literally) checks if the function that you call exists in the WordPress library. If it does not exist, it won’t break your blog saying that the page has called an “undefined function” rather hide the function until it becomes defined.
The Example:
Take a look at the two methods of calling the famous “Related Posts” plugin for WordPress:
1. - <?php related_posts(); ?>
2. - <?php
if (function_exists('related_posts')) {
related_posts(); }
?>
The first example will work fine, that is until you move the plugin files or modify any of the parameters. Then it will result in an error code that hijacks your blog until you fix the problem. If you’ve left on a vacation or don’t look at the blog for a few days, then you’ve lost all that traffic and new readership. Not so good for growth now is it? ![]()
The second example is much more ideal for any WordPress installation. This code won’t hijack your blog with an error code, rather hide the function all together.
The Conclusion:
If you are serious about blogging and want to expand your reach as far as possible, error codes will not help you. Use the if (function_exists) call when adding plugins to your WordPress theme… you’ll thank yourself if you ever run into trouble.






20 Comments
Thnx for the info! I just got of another blog where I was trying to post a comment and ended up with a blank page……just a little frustrating. I’m going to ask my programmer about this option as a fail-safe against the dreaded white screen.
Yeah, the white screen is usually a sign of a bad plugin or modification to WordPress. I continually test my site to ensure that it is running to its full capability
Thank you Brad, very helpful!
JR @ Internet Marketing ´s last blog ..List of 132 Comment Luv Blogs by Niche
Glad you found it useful!
Hmmm…to risk!!
bee´s last blog ..Powerful Earthquake has Destroy Haitian Country
Indeed?
Exists function is an essential code to install with plugin.

Jayce´s last blog ..HTC HD2 Real Media video player
Glad to hear it Jayce… I’ve used the dangerous method above of calling plugins before and have regretted it in the future.
so, where we’d enter this particular code exactly?
Codrut Turcanu´s last blog ..The Best PLR Article Pack Offer
You would put this code wherever you call a plugin to preform a task for you – I.E. “Related Posts” in the sidebar.
Which is where, like in which file do you insert the code? Most of us just activate the plugins because we don’t know where this code goes. Is it possible to provide a link where you have explained where the code goes?
Charlie´s last blog ..Walz Visits With Top 10 Recruit
Brad,
Nice tip. I find I struggle with this, though. For me, this is advanced PHP already.
Because I use a WP blog at work, I think I should get much, much better at it. Aside from reading blogs like yours, do you have any suggestions for someone getting started? I’ve learned other bits and pieces of coding on my own in the past (Visual Basic, HTML, stuff like that). Where did you get your start?
Gomez the windshield monkey´s last blog ..The weather and your windshield
I honestly started by experimenting with websites and blogs. Changing things to see what there effect would be on the design and functionality.
Set up a blog and just begin to play with various settings, you’d be amazed at what you can do!
Advanced PHP, I agree. All we do with plugins is install and activate. We don’t know what gets written and where it’s written. I do know however of some plugins where you get to write it yourself like in the case of the wp-contactform plugin where we need to write in the page something like ‘% % wpcontactform % %’ or in the template, ”.
Anyway, this post gave me reason to dive under my blog’s hood and check out what I can do to make it plugin-proof.
Jenny M.´s last blog ..100 ft Ethernet Cable
Yeah, you can even make it disappear if you do the wrong thing.
Charlie´s last blog ..Walz Visits With Top 10 Recruit
Thank! I will try it on my wordpress in my localhost! thank!
Sereboth´s last blog ..When can Cambodian withdraw money from Paypal?
Very useful info. Thanks for share
zohaib´s last blog ..50 Dazzling Retro Style Posters
Thanks for the info. This is really interesting to as I’m new with WP.
I wonder if Kyle Eslick at wphacks.com cares that you totally ripped his post from back in 2007.
I had no knowledge of Kyle writing a similar article. This post was completely independent of that website and came from my own knowledge.
Please get your facts straight before you accuse.