使用以下代码尝试将页面 slug 作为一个类添加到我的 body 标记中,但尚未成功,谁能告诉我如何实现这一目标?
在functions.php中添加PHP
function add_body_class( $classes )
{
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
add_filter( 'body_class', 'add_body_class' );