Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active October 29, 2016 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save srikat/471dc097f8f1099033f0 to your computer and use it in GitHub Desktop.
Save srikat/471dc097f8f1099033f0 to your computer and use it in GitHub Desktop.
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