Site logo

Archived topic

Hook for page and all subpages

3 replies · Started by Michal on August 27, 2019

Viewing posts 1–4 of 4

Hello,
is there any way to display the hook on the parent page and all the subpages of this parent page automatically?

In display rules section I can choose only concrete pages one by one.

Hi there,

This topic might help: https://generatepress.com/forums/topic/conditionally-display-hook-on-sub-page-of-parent/

For example:

add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
    global $post;

    if ( 1180 === $element_id && ( is_page() && $post->post_parent == '415' ) ) {
        $display = true;
    }

    return $display;
}, 10, 2 );

You need to replace 1180 with the ID of your Element, and 415 with the ID of the parent page.

Great it works perfectly :)

Awesome :)

This archived topic is closed to new replies.