Archived topic
Element set visibility on all pages with a specific page parent
5 replies · Started by Matthew on September 10, 2020
Hi
Is it this possible? I don't think it is unless I have missed something?
So basically if 20 pages have a parent page called "123" set an element to appear on all pages with the parent "123"?
If its not possible I would love to suggest this as a feature. 😀
Cheers
Hi there,
Take a look at the second example here:
https://docs.generatepress.com/article/generate_hook_element_display/
That is fantastic Leo!
Just a quick one though, to avoid just duplicate this code, how could I have an element load on multiple parents/childs?
E.g. say the element ID is 1180 (like in the example) and I want this to load on child for 415 and 420 (random examples).
I assume this is fairly simple if you know what you are doing, I do not. Haha.
It would be something like this:
add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
global $post;
if ( 1180 === $element_id && ( is_page() && $post->post_parent == '415' ) || 1180 === $element_id && ( is_page() && $post->post_parent == '420' ) ) {
$display = true;
}
return $display;
}, 10, 2 );
Awesome thank you :)
No problem :)