• I want to hide the header on one specific category (slug: thank-you)
    I tried the following:

    .single-post .category-thank-you .site-header,
    .single-post .category-thank-you .header-image {
      display: none;
    }

    And

    .category-thank-you .site-header,
    .category-thank-you .header-image {
      display: none;
    }

    I add the tag !important;

    But none works.

    Is there any way to get this done?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hello there,

    Could you please share one of the link to the pages in question, so I can take a closer look?

    Regards,
    Kharis

    Thread Starter idoa

    (@idoa)

    Hey Kharis,

    Sure,

    Here is 1
    https://idt.workfromhomeblog.info/spl-thanks/
    Here is 2
    https://idt.workfromhomeblog.info/thank-you/

    thank you very much.
    Ido

    Dear Ido,

    Every page comes with a unique class name attached to the body tag. Try to use the following CSS code:

    .postid-556 .site-header,
    .postid-556 .header-image{
      display: none;
    }

    556 is the post ID of https://idt.workfromhomeblog.info/spl-thanks/. To find it, please see this post.

    Regards,
    Kharis

    Thread Starter idoa

    (@idoa)

    Hey Kharis,

    yes i have this one (this way)

    .single-post.postid-556 .site-header,
    .single-post.postid-556 .header-image {
      display: none;
    }

    i was hoping to find a way to do this on the entire category a i have many different post in it that need to look the same.

    thanks again for all your help
    Ido

    Dear Ido,

    To do so, you have to add category slug name to the body class of single post page. Add this function into the child theme’s functions.php or use Functionality plugin.

    /*
     * Add category slug to single post's body
     * Source: https://css-tricks.com/snippets/wordpress/add-category-name-body_class/
    */
    add_filter('body_class','add_category_to_single');
    function add_category_to_single($classes, $class) {
      if (is_single() ) {
        global $post;
        foreach((get_the_category($post->ID)) as $category) {
          // add category slug to the $classes array
          $classes[] = $category->category_nicename;
        }
      }
      // return the $classes array
      return $classes;
    }

    Now you can apply the following CSS code:

    .single-post.category-thank-you .site-header,
    .single-post.category-thank-you .header-image {
      display: none;
    }
    
    .category-thank-you .site-header,
    .category-thank-you .header-image {
      display: none;
    }

    Regards,
    Kharis

    Thread Starter idoa

    (@idoa)

    Hey Kharis,

    Thanks again for all your help,

    I’m sorry for being a pain but when i do that i get the following error message

    <b>Warning</b>:  Missing argument 2 for add_category_to_single() in <b>/home/holygepu/public_html/wp-content/themes/?????-?????-???????/functions.php</b> on line 22 class="single single-post postid-556 single-format-standard siteorigin-panels wc-shortcodes-font-awesome-enabled ms-guest ms-0 thank-you group-blog">

    You can see it here:
    https://idt.workfromhomeblog.info/spl-thanks/

    Thank you very much.
    Ido

    Hello Ido,

    Thank you for the followup. Sorry for the trouble.

    Please replace this line:

    function add_category_to_single($classes, $class) {

    with:

    function add_category_to_single($classes) {

    Regards,
    Kharis

    Thread Starter idoa

    (@idoa)

    Hey Kharis,

    Thanks a lot.

    I’ve replaced this line, and the warning is gone, but its not working- the header and header-image are still showing.

    https://idt.workfromhomeblog.info/spl-thanks/
    https://idt.workfromhomeblog.info/thank-you/

    sorry for all this and thank you again
    Ido

    Dear Ido,

    Thank you for updating me. I noticed that the category slug is applied to the body tag already.

    Sorry for suggesting wrong CSS code. You don’t need to precede the category slug with category-. Please try this code instead:

    .single-post.thank-you .site-header,
    .single-post.thank-you .header-image {
      display: none;
    }
    
    .thank-you .site-header,
    .thank-you .header-image {
      display: none;
    }

    Regards,
    Kharis

    Thread Starter idoa

    (@idoa)

    Perfect

    Wow Kharis, thank you so much,

    This is exactly what I needed.

    You are the best!

    No problem.

    I am glad to know it is working for you at this time! Please let us know if you have any further questions, or if we can provide you with any other assistance.

    Regards,
    Kharis

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Hide the header on one specific category’ is closed to new replies.