Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Hero Block: Don’t display beyond first page of results

  • 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.

  • 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 🙂

  • I’ve got WP Code Lite and added the snippet there.

    No change. Still not working.

  • 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?

  • 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.

  • I did that and checked again but nothing changed.

  • Hi there,

    I tried logging in with the credentials provided, but it’s not working. Can you check if they are correct?

  • Try it now. I reset the password to something else.

  • Can you set Inherit Query from Template first? Example: https://share.getcloudapp.com/p9uZDbqP

    We’ll then assess what to do next.

  • 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.

  • 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.

  • 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 );
Viewing 16 posts - 1 through 16 (of 19 total)
  • You must be logged in to reply to this topic.