Archived topic
GP Premium Elements - apply a hook or layout to all child-pages of a parent-page
7 replies · Started by Adrian on January 24, 2022
Hello GP Team,
thank you for your great work.
Is there a way to assign a hook or layout to all child-pages on a parent-page?
I am working on a page with many subpages that are also automatically filled. In order to avoid having to manually update the list of pages for a hook every time after an update, it would be handy if I could assign the hook or layout to all sub/child-pages of a page X. Is there a way to do this?
Thanks in advance
Adrian
Hi there,
see my reply here:
https://generatepress.com/forums/topic/block-hook-on-all-sub-pages/#post-2086138
Nice. Thank you.
You're welcome
It's working, thank you.
Would it be possible to extend your PHP snippet with a query for the user role? In my case, only logged-in users should have access to these specific elements or be able to see them.
add_filter( 'generate_element_display', function( $display, $element_id ) {
global $post;
if ( 4689 === $element_id && 4684 == $post->post_parent ) {
$display = true;
}
return $display;
}, 10, 2 );
Thank you very much!
This line:
if ( 4689 === $element_id && 4684 == $post->post_parent ) {
try changing to:
if ( 4689 === $element_id && 4684 == $post->post_parent && is_user_logged_in() ) {
Sorry for the late reply. The code works perfectly. Thank you very much! I should get more into PHP ;-)
Glad to be of help!