admin管理员组文章数量:1122832
I have added this code to my child theme's functions.php
file and use the new class but it styles the entire site, not the page I added to the code. What am I doing wrong?
add_filter('body_class','custom_body_class');
function custom_body_class($classes) {
if( is_page('38034') ) {
$classes[] = 'new-class';
return $classes;
}
}
I have added this code to my child theme's functions.php
file and use the new class but it styles the entire site, not the page I added to the code. What am I doing wrong?
add_filter('body_class','custom_body_class');
function custom_body_class($classes) {
if( is_page('38034') ) {
$classes[] = 'new-class';
return $classes;
}
}
Share
Improve this question
edited Apr 30, 2013 at 8:14
Haymanpl
asked Apr 30, 2013 at 7:52
HaymanplHaymanpl
931 gold badge5 silver badges9 bronze badges
2
|
2 Answers
Reset to default 8The ID can/should be given without quotes (otherwise if you a page with '38034' as slug/post_name, this will be used instead of the page with the ID 38034). And you want to return $classes
no matter if you added your own or not.
add_filter('body_class', 'custom_body_class');
function custom_body_class($classes) {
if (is_page(38034))
$classes[] = 'new-class';
return $classes;
}
Your function name does not match. Try this..
add_filter( 'body_class', 'custom_body_class' );
function custom_body_class( $classes ) {
if ( is_page( '38034' ) ) {
$classes[] = 'new-class';
return $classes;
}
}
本文标签: How do I add a custom body class for a specific page ID
版权声明:本文标题:How do I add a custom body class for a specific page ID? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736298522a1930243.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
return $classes;
would need to be outside of theif( is_page() )
– Michael Commented Apr 30, 2013 at 9:24