Skip to content

Instantly share code, notes, and snippets.

@zackpyle
Created May 18, 2023 18:37
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 zackpyle/0f33f9f86b37adb14c7849975a6d4aad to your computer and use it in GitHub Desktop.
Save zackpyle/0f33f9f86b37adb14c7849975a6d4aad to your computer and use it in GitHub Desktop.
Adds page slub to the body class prepended by the post type name
<?php // ignore this line - only for styling
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
add_filter( 'body_class', 'add_slug_body_class' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment