Skip to content

Instantly share code, notes, and snippets.

@donnamcmaster
Created April 6, 2017 21:57
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 donnamcmaster/e5091aee1773823335e2c3e77962e102 to your computer and use it in GitHub Desktop.
Save donnamcmaster/e5091aee1773823335e2c3e77962e102 to your computer and use it in GitHub Desktop.
WordPress: adds the post type and slug to the <body> class, e.g., "page-about"
<?php
/**
* Adds the post type and slug to the <body> class, e.g., "page-about".
*/
add_filter( 'body_class', function( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[]= "{$post->post_type}-{$post->post_name}";
}
return $classes;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment