Skip to content

Instantly share code, notes, and snippets.

@ramseyp ramseyp/if_exists.php
Last active Aug 29, 2015

Embed
What would you like to do?
Check to see if something exists before you call some function / class / method in your WordPress functions.php
<?php
if ( function_exists( 'function_name' ) ) {
//... do something ...
}
if ( class_exists( 'Class_Name' ) ) {
//... do something ...
}
// You can also use the negative !
if ( !function_exists( 'function_name' ) ) {
//... do something ...
}
if ( !class_exists( 'Class_Name' ) ) {
//... do something ...
}
/**
* Example: Manually load Jetpack's Sharing buttons in your theme
*
*/
if ( class_exists( 'Sharing_Service' ) ) {
echo sharing_display();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.