Black Friday Sale! Get up to $30 off GP Premium! Learn more ➝

[Resolved] GP Hook on certain child pages

Home Forums Support [Resolved] GP Hook on certain child pages

Home Forums Support GP Hook on certain child pages

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #1056154

    Hi There,

    I’m trying to display a hook (ID = 18275)
    only on child pages of a certain page (ID = 98).

    At the moment I can only get it to display on child pages AND the parent page so I’m obviously doing something wrong!

    Lead Developer
    Lead Developer

    Hi there,

    How are you currently displaying it on child and parent pages?

    If you want, we can filter the hook to display on all child pages of a specific parent:

    add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
        global $post;
        if ( 123 === $element_id && ( is_page() && 456 == $post->post_parent ) ) {
            $display = true;
        return $display;
    }, 10, 2 );

    In the above, you just need to replace 123 with the ID of the hook you’re targeting, and 456 with the ID of the parent page.


    Hi Tom,

    Thanks for this, I’ve added this to functions.php it was slightly different from the snippet I’d got from the knowledgebase.

    It’s still appearing on all inner pages, however.

    Here’s the display settings on the element itself, do these have to be different?





    Ok so, i’ve change the display rule to just display on the parent page and that seems to have stopped it showing on other pages.

    So now it’s displaying on the parent page (training courses) and child pages of that parent.

    I just need to exclude the training course parent page.



    So, just documenting this for anyone that stumbles across this forum post.

    I set the display rule to one of the child pages (a random one) and set an exclusion rule to exclude the parent page.

    I added Tom’s code from above to functions.php and this now displays the element on all child pages.

    It seems as though the function doesn’t override the element display rule but runs alongside it.

    Lead Developer
    Lead Developer

    Glad you got it working – thanks for letting us know! 🙂


    Is there any chance this could be a feature?

    Having a display rule that allows us to set “Page” and “Child of” would be rather useful for anyone wanting to have the same header on a group of pages or color theming different areas of a site.

    Lead Developer
    Lead Developer

    Agreed, this would be nice. Definitely something I’ll look at adding 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.