Archived topic
Can I Assign an Element to Every Page with a Certain Parent?
4 replies · Started by Samuel on November 3, 2020
I have a situation where I have several pages that are child pages of a certain page. I want all the child pages to use the same page header, but right now I keep adding rules to the element to cover every page. Is there a way to say that every child of a certain page should inherit a specific page header?
Hi,
We'll have to use the generate_hook_element_display filter for this.
add_filter('generate_header_element_display' , function( $display, $element_id ){
if( $element_id === 18769 && is_page() && $post->post_parent == 18053 ){
$display = true;
}
return $display;
});
Just replace 18769 with your Header element ID and 18053 with your parent page's page ID.
It would be great to have it built-in too ;-)
Thank you I will use that but would be great to have built it :)
Thank you I will use that but would be great to have built it
Hi @Fabien & @Samuel,
You can open a topic asking this as a feature request.
Alternatively, you can raise an issue on our github page asking for it as a feature request.
https://github.com/tomusborne/generatepress/issues