Site logo

Archived topic

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

13 replies · Started by Lewis on November 3, 2021

Viewing posts 1–14 of 14

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?

Hi there,

try changing the condition:

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

to:

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

That hasn't worked sorry David.

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

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

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

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

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

    return $display;
} );

Here you go

Try:

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

  return $display;
} );

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

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

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.

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 );

There we have it!

Thanks for working through that David.

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

This archived topic is closed to new replies.