[Resolved] How to Hide Header from Page 2/3/4 of Blog

Home Forums Support [Resolved] How to Hide Header from Page 2/3/4 of Blog

Home Forums Support How to Hide Header from Page 2/3/4 of Blog

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1990030
    Lewis

    I’m looking to hide a header element from page 2 onwards of my blog. I’ve tried a code I found on the forum to hide the header which works fine BUT it also hides my category headers for pages 2 onwards which I don’t want to happen.

    I only want to apply this to the homepage header.

    I’ve also tried the following:

    add_filter( 'generate_block_element_display', function( $display ) {
      if ( 6125 === $element_id && is_paged() ) {
         $display = false;
      }
    
      return $display;
    } );

    But that fails on me.

    Any ideas?

    #1990042
    David
    Staff
    Customer Support

    Hi there,

    try changing the condition:

    if ( 6125 === $element_id && is_paged() ) {

    to:

    if ( 6125 === $element_id && is_paged() && !is_category() ) {

    #1990045
    Lewis

    That hasn’t worked sorry David.

    Just to confirm 6125 is the element ID of the homepage header.

    #1990067
    David
    Staff
    Customer Support

    Do you have separate Elements for the Home and the Category archives ?

    #1990070
    Lewis

    Yes I do. Both are header elements but they are separate. Homepage header is only used for front page.

    #1990099
    David
    Staff
    Customer Support

    What code do you have that is working – but also affecting the categories?

    #1990102
    Lewis
    add_filter( 'generate_header_element_display', function( $display ) {
        if ( is_paged() ) {
           $display = false;
        }
    
        return $display;
    } );

    Here you go

    #1990114
    David
    Staff
    Customer Support

    Try:

    add_filter( 'generate_element_display', function( $display ) {
      if ( 6125 === $element_id && is_paged() ) {
         $display = false;
      }
    
      return $display;
    } );
    #1990129
    Lewis

    No luck I’m afraid. I’ve shared the URL of the offending page where it is still showing in the private information section.

    #1990176
    David
    Staff
    Customer Support

    Can you edit the Header Element and check the URL to make sure the 6125 is the ID?

    #1990179
    Lewis

    Can confirm it is 6125. URL is:

    wp-admin/post.php?post=6125&action=edit

    I have also cleared cache just to confirm that’s not blocking anything and still no luck.

    #1990189
    David
    Staff
    Customer Support

    Doh! Missed the obvious:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 6125 === $element_id && is_paged() ) {
           $display = false;
        }
    
        return $display;
    }, 10, 2 );
    #1990191
    Lewis

    There we have it!

    Thanks for working through that David.

    #1990205
    David
    Staff
    Customer Support

    Sorry about that – don’t know what i was thinking.
    Glad to be of help!

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.