Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save qstudio/9325333 to your computer and use it in GitHub Desktop.
Save qstudio/9325333 to your computer and use it in GitHub Desktop.
WP - add post slug and post_type to page body classes
<?php
// add filter to body_class
add_filter( 'body_class', 'q_body_class', 1 );
/*
* add extra classes to html body tag
*/
function q_body_class( $classes ) {
// get $post object ##
global $post;
if ( $post ) {
$classes[] = $post->post_type . '-' . $post->post_name; // posttype-slug ##
$classes[] = $post->post_name; // post-slug ##
}
// return classes ##
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment