Skip to content

Instantly share code, notes, and snippets.

@BeardedGinger
Created February 27, 2017 20:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BeardedGinger/eb09a1fa3cf0e3ce0a65feee88c8fc64 to your computer and use it in GitHub Desktop.
Save BeardedGinger/eb09a1fa3cf0e3ce0a65feee88c8fc64 to your computer and use it in GitHub Desktop.
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
Copy link

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

@warnakey
Copy link

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