Home / Archive / Add the Page Slug to Body Class
Duplicate Snippet

Embed Snippet on Your Site

Add the Page Slug to Body Class

Add the page slug to the body class for better styling.

2.1k
Code Preview
php
<?php
function wpcode_snippet_add_slug_body_class( $classes ) {
	global $post;
	if ( isset( $post ) ) {
		$classes[] = $post->post_type . '-' . $post->post_name;
	}
	return $classes;
}
add_filter( 'body_class', 'wpcode_snippet_add_slug_body_class' );

Comments

Add a Comment