Skip to content

Instantly share code, notes, and snippets.

@ramseyp
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramseyp/8812180 to your computer and use it in GitHub Desktop.
Save ramseyp/8812180 to your computer and use it in GitHub Desktop.
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