2018-06-12 05:59
浏览 37


I have unique theme for WP and I need to add different classes into tag body if user come to these pages. (Example for I need tag body with class ="body page_body" for I need tag body with class ="body page_news" ) How can I get it ? In Internet I found tip like - write in functions.php

function my_body_class_filter( $classes ) {
global $post;

if ( $post ) {
    $classes[] = $post->post_name;

return $classes;

} add_filter( 'body_class', 'my_body_class_filter' );

and in header.php

<body <?php body_class(); ?> 

But I got a lot of classes I don't need so many classes. Can someone recommend a filter by slug for pages ?

图片转代码服务由CSDN问答提供 功能建议

我有WP的独特主题,如果用户访问这些页面,我需要在标签正文中添加不同的类。 (示例以示例说明/我需要使用class =“body page_body”的标签体,例如/ news /我需要带有class =“body page_news”的标签体)我怎样才能得到它? 在互联网上,我在functions.php </ p>

  function my_body_class_filter($ classes){
global $ post; 
if($ post){\  n $ classes [] = $ post-&gt; post_name; 
return $ classes; 
 </ code> </ pre> 

} add_filter('body_class',' my_body_class_filter'); </ p>

和header.php </ p>

 &lt; body&lt;?php body_class();  ?&GT;  
 </ code> </ pre> 

但我有很多课程 https:// 我不需要这么多课程。 有人可以推荐一个针对页面的slug过滤器吗?</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题