Last active
June 1, 2018 10:10
-
-
Save ScarletPonytail/8267821e2f963a5ba75810447c1f9ab3 to your computer and use it in GitHub Desktop.
PHP - How to check for a class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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