Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to add Page slug as a body class for static Pages in WordPress. https://sridharkatakam.com/add-page-slug-body-class-static-pages-wordpress/
add_filter( 'body_class', 'sk_body_class_for_pages' );
/**
* Adds a css class to the body element
*
* @param array $classes the current body classes
* @return array $classes modified classes
*/
function sk_body_class_for_pages( $classes ) {
if ( is_singular( 'page' ) ) {
global $post;
$classes[] = 'page-' . $post->post_name;
}
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment