[Resolved] Exclude text from pagination pages from elements block Hook

Home Forums Support Exclude text from pagination pages from elements block Hook

  • This topic has 9 replies, 4 voices, and was last updated 4 months ago by Tom.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1505817
    Alessandro

    Hi, I inserted an intro text on the home page, but I would like it not to be repeated in the pagination pages /page/2/ /page/3/ …

    How can I do?

    #1505979
    David
    Staff
    Customer Support

    Hi there,

    you can add this PHP Snippet to exclude a specific Block Element when visiting a paged instance:

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

    The 123 has to be replaced with the Block Elements ID – you can get this by editing the Block element and checking the URL in the browser.

    #1506109
    Alessandro

    Thanks David, but the modify don’t show.
    I use a child theme, but strangely, the css and the function.php changes are not read either.
    Currently in the child there is this content:

    
    <?php
    /**
     * GeneratePress child theme functions and definitions.
     *
     * Add your custom PHP in this file.
     * Only edit this file if you have direct access to it on your server (to fix errors if they happen).
     */
    function generatepress_child_enqueue_scripts() {
    	if ( is_rtl() ) {
    		wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' );
    	}
    }
    add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );
    
    add_filter( 'generate_google_font_display', function() {
        return 'swap';
    } );
    
    function no_self_ping( &$links ) {
        $home = get_option( 'home' );
        foreach ( $links as $l => $link )
            if ( 0 === strpos( $link, $home ) )
                unset($links[$l]);
    }
     
    add_action( 'pre_ping', 'no_self_ping' );
    
    add_filter( 'generate_block_element_display', function( $display ) {
      if ( 434 === $element_id && is_paged() ) {
         $display = false;
      }
    
      return $display;
    } );
    
    #1506820
    Leo
    Staff
    Customer Support

    Can you clear and disable your caching plugin first?

    #1508024
    Alessandro

    plugin disabled and cache deleted.
    Unfortunately the problem persists.

    #1508107
    David
    Staff
    Customer Support

    Can you try moving the function i provided to the just below this function:

    function generatepress_child_enqueue_scripts() {
    	if ( is_rtl() ) {
    		wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' );
    	}
    }
    add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );
    #1508154
    Alessandro

    Done, no change.
    If it helps, I’ll send you access to WP in tried.

    #1508532
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this, instead:

    add_filter( 'generate_block_element_display', function( $display, $element_id ) {
      if ( 123 === $element_id && is_paged() ) {
         $display = false;
      }
    
      return $display;
    }, 10, 2 );
    #1509266
    Alessandro

    Thanks Tom, now it works πŸ™‚

    #1509896
    Tom
    Lead Developer
    Lead Developer
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.