Last active
November 10, 2019 16:57
-
-
Save andymagill/c605580c452e8a7aa114070fac999ce4 to your computer and use it in GitHub Desktop.
Add unique class to body tag - WordPress
This file contains hidden or 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
<?php | |
// Add page name to body classes | |
function add_page_name_class($classes) | |
{ | |
global $post; | |
if ( is_page() || is_singular() ) { | |
$classes[] = sanitize_html_class($post->post_name); | |
} | |
return $classes; | |
} | |
add_filter('body_class', 'add_page_name_class'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment