-
-
Save BeardedGinger/eb09a1fa3cf0e3ce0a65feee88c8fc64 to your computer and use it in GitHub Desktop.
Check whether a page contains a given body class.
This file contains 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
<?php | |
/** | |
* Conditional to check whether or not the body class contains a given class. | |
* | |
* @param string $class The class we're lookging for in the body class. | |
*/ | |
function has_body_class( $class ) { | |
$body_classes = get_body_class(); | |
return in_array( $class, $body_classes, true ); | |
} |
Thank you for sharing this. It's exactly what I needed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @BeardedGinger,
I added a custom class to one of my page that displays the results of a filtering plugin.
The php file used to render the results cannot be used anymore in conditionals within function.
Let's say my class is "my-class", how would I use your function to make a condition for instance to remove a breadcrumb on that specific page?
Thank you