Skip to content

Instantly share code, notes, and snippets.

@navalon
Forked from srikat/functions.php
Created October 29, 2016 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navalon/e5fe2ce36bf8e4bf0e9b637de387da50 to your computer and use it in GitHub Desktop.
Save navalon/e5fe2ce36bf8e4bf0e9b637de387da50 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