Site logo

Archived topic

Exclude Hook Element and Block Element from Paginated Pages

3 replies · Started by Vish on February 8, 2022

Viewing posts 1–4 of 4

Hello

I have a Hook Element and a Header Element set to "Front Page" in display rules.

I want this to show up only in the front page and not in the paginated pages.

I placed the below code in functions.php of the child theme:

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

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

Still both the elements show up in the paginated pages.

Site URL provided in the private informtation area.

Ying - It works fine as I added a different code. The old way does not work anymore.

In case anyone else is looking for the solution:

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

    return $display;
}, 10, 2 );

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

    return $display;
}, 10, 2 );

Where 36 and 285 are the IDs of the elements.

The code seems fine :)

Thanks for sharing!

This archived topic is closed to new replies.