Checking to see if built in WordPress functions exist before calling them is for backward compatibility which IMHO is not needed.
So if you see if ( function_exists( 'register_nav_menus' ) )
the theme author is supporting versions earlier than 3.0.
You still sometimes see if ( function_exists( 'dynamic_sidebar' ) )
Why? I couldn’t tell you because dynamic_sidebar was introduced.
Another reason to use it is to make your theme or plugin pluggable. A pluggable function is one that can be overridden in a child theme or another plugin.
This is done on the definition not the call and you use the ! operator to make sure it doesn’t already exist before you define it.
1 2 3 4 5 6 7 8 9 10 11 12 | if ( ! function_exists( 'my_awesome_function' ) ) { /** * My Awesome function is awesome * * @param array $args * @return array */ function my_awesome_function( $args ) { //function stuff return array(); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.