Skip to content

Instantly share code, notes, and snippets.

@ScarletPonytail
Last active June 1, 2018 10:10
Show Gist options
  • Save ScarletPonytail/8267821e2f963a5ba75810447c1f9ab3 to your computer and use it in GitHub Desktop.
Save ScarletPonytail/8267821e2f963a5ba75810447c1f9ab3 to your computer and use it in GitHub Desktop.
PHP - How to check for a class
function the_thing() {
$classes = get_body_class();
if( in_array( 'the-class', $classes, true ) ) {
// Do a thing
}
}
// or
function the_thing() {
if( class_exists( 'foo' ) ) {
// Do a thing
}
else {
// Do another thing
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment