-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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