- This topic has 8 replies, 2 voices, and was last updated 2 years, 1 month ago by
Tom.
-
AuthorPosts
-
November 7, 2019 at 9:17 am #1056154
Ashley
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!
November 7, 2019 at 6:34 pm #1056464Tom
Lead DeveloperLead DeveloperHi 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, and456
with the ID of the parent page.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentNovember 8, 2019 at 1:02 am #1056609Ashley
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?
November 8, 2019 at 1:05 am #1056611Ashley
November 8, 2019 at 1:07 am #1056615Ashley
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.
November 8, 2019 at 1:10 am #1056616Ashley
[SOLVED]
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.
November 8, 2019 at 9:52 am #1057184Tom
Lead DeveloperLead DeveloperGlad you got it working – thanks for letting us know! ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 19, 2020 at 3:38 am #1586845Alexander
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.
December 19, 2020 at 12:39 pm #1587433Tom
Lead DeveloperLead DeveloperAgreed, this would be nice. Definitely something I’ll look at adding ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.