Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add Page Slug as Body Class
//* Do NOT include the opening php tag shown above. Copy the code shown below.
add_filter( 'body_class', 'wps_add_slug_body_class' );
* Add Page Slug as Body Class.
function wps_add_slug_body_class( $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