-
datatv
I’ve got a hero block on my homepage as well as on my archives (https://fwtmagazine.com/staging). When you go to Page 2 and beyond, I’d like the hero to go away and we just focus on the post grid. Is there a setting to allow me to incorporate that?
-
Hi there,
you can use this PHP Snippet to remove it:
add_filter( 'generate_element_display', function( $display ) { if ( 99 === $element_id && is_paged() ) { $display = false; } return $display; } );
Change the
99
to the ID of your element, which you can get by editing the element and checking the browser url field. -
datatv
That didn’t work. I added it to my child theme’s functions.php and check it out in an incognito browser window and still seeing the hero on page two and beyond.
Just to be clear, the ID of the element is what you see if the URL around post=12345 where 12345 would be the ID?
-
Yes, that’s the element’s id.
Can you try adding the code via a plugin like code snippet to test?
Let me know 🙂
-
datatv
I’ve got WP Code Lite and added the snippet there.
No change. Still not working.
-
datatv
I should mention I added it as a PHP Snippet.
-
It is a PHP snippet.
Can you provide the admin login so I can take a look at the backend setup?
-
datatv
I’m enclosing it in the private info window.
-
Aah, your Query Loop has fixed parameters so its pagination only applies to the query it runs, not the page itself.
To fix that edit the Query Loop, remove the Parameters and set it to
Inherit Query from Template
Do that and then we’ll review how to exclude the hero post from the loop.
-
datatv
I did that and checked again but nothing changed.
-
Fernando
Hi there,
I tried logging in with the credentials provided, but it’s not working. Can you check if they are correct?
-
datatv
Try it now. I reset the password to something else.
-
Fernando
Can you set
Inherit Query from Template
first? Example: https://share.getcloudapp.com/p9uZDbqPWe’ll then assess what to do next.
-
datatv
Oh, I thought you wanted that setting applied to the hero block. Not the post grid.
Guess you should explain it in a bit better detail in the future. Thankfully, this isn’t going live just yet.
Settings are switched, but I’m still seeing the hero on every page.
-
Fernando
I see. Sorry for not being clear.
Can you try to change the code to this:
add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 33498 === $element_id && is_paged() ) { $display = false; } return $display; }, 10, 2 );
Let me know how it goes.
-
datatv
It worked! Almost there. So thanks for everything so far.
I’ve got a number of heroes that are meant to display the first post over different category archives. So I need to modify this slightly to respect all element ID’s. What would work? I tried this but it definitely did not.
add_filter( 'generate_element_display', function( $display, $element_id ) { if isArray( [33498, 33659, 33662, 33666]) === $element_id && is_paged() ) { $display = false; } return $display; }, 10, 2 );
I also tried:
add_filter( 'generate_element_display', function( $display, $element_id ) { if ( array("33498", "33659", "33662", "33666") === $element_id && is_paged() ) { $display = false; } return $display; }, 10, 2 );
- You must be logged in to reply to this topic.