2015-06-16 17:41
浏览 44


I have a Wordpress site and I want to change certain CSS values in the header.php on the index page only. I have a div which is 100% width and border bottom to add an underline to the header.php

<div class="nav"> 

   ...content to create nav-bar ...

    <div class="hr"></div> <!-- remove on index.php -->


I don't want it to show, or affect anything on the index.php. (I don't want to target another header.php file for this one small thing)

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanlai1855 2015-06-16 17:52

    Wordpress has a template tag called body_class which is used to create contextual CSS hooks.

    <body <?php body_class(); ?>>

    You can then use it in your CSS as follows:

    .blog {}
    .blog.home {}
    /** if blog index is a page **/
    .page.blog {}

    see the documentation for the rather extensive list of possible output.

    打赏 评论
  • dpw30157 2015-06-16 17:45

    Usually, by default, in a Wordpress site, the body element has a home class for the front page.

    So in your CSS you could try the following:

    .home .nav .hr { display:none; }
    打赏 评论

相关推荐 更多相似问题