Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check whether a page contains a given body class.
<?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 );
}
@Franz333

This comment has been minimized.

Copy link

@Franz333 Franz333 commented Sep 19, 2018

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

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.