Skip to content

Instantly share code, notes, and snippets.

@andymagill
Last active November 10, 2019 16:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andymagill/c605580c452e8a7aa114070fac999ce4 to your computer and use it in GitHub Desktop.
Save andymagill/c605580c452e8a7aa114070fac999ce4 to your computer and use it in GitHub Desktop.
Add unique class to body tag - WordPress
<?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