Site logo

Archived topic

Exclude text from pagination pages from elements block Hook

13 replies · Started by Alessandro on October 27, 2020

Viewing posts 1–14 of 14

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?

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.

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

Can you clear and disable your caching plugin first?

plugin disabled and cache deleted.
Unfortunately the problem persists.

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

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

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

Thanks Tom, now it works :)

You're welcome :)

Hi,
i have the same problem on another website.
I have test the first and second code, but don't work. It's an "Header" type.
How can i do?

thank you David!

Work perfectly.
Have a nice day
Alessandro

you're welcome

This archived topic is closed to new replies.