Hey! So wasn’t sure if you wanted a really short answer, but this is what I add to my functions.php (at the very end).
If there is a closing ‘?>’ at the end of functions.php, then add below code before that.
The code:
// Add page slug (name) to body class
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_name;
}
return $classes;
}
add_filter( ‘body_class’, ‘add_slug_body_class’ );
This will add your page slug name (which IS the page url) to your body’s class attribute (for that page). So if you’re on the about page (with slug …/about-me), it will add the class about-me to your body tag.
If you’re trying to have unique slugs, not numbers, go to Settings->Permalinks…
Then set Custom Structure to ‘/%postname%’