Skip to content

Instantly share code, notes, and snippets.

@Archie22is
Created August 17, 2022 06:32
Show Gist options
  • Select an option

  • Save Archie22is/4aef1e55ed8a9c58f18ef8a941d6c2a3 to your computer and use it in GitHub Desktop.

Select an option

Save Archie22is/4aef1e55ed8a9c58f18ef8a941d6c2a3 to your computer and use it in GitHub Desktop.
Display page slug body class
<?php
/**
* Page slug body class
* https://www.wpbeginner.com/wp-themes/how-to-add-page-slug-in-body-class-of-your-wordpress-themes/
*
*/
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