Archived topic
Display Elements via filters
3 replies · Started by melanie on December 21, 2018
I have several custom headers (elements) that I would like to display via filters vs. adding a long page list. I wrote the function but something must be wrong. Any pointers?
//Apply Custom Page Header based on Ancestor
add_filter( 'generate_header_element_display', function( $display, $element_id ) {
if ( 45458 === $element_id && is_array( $ancestors ) && in_array( 44258, $ancestors ) ) {
$display = true;
}
return $display;
}, 10, 2 );
Hi there,
You don't seem to have anything defined as $ancestors.
Are you trying to target a list of regular pages, or a list of child pages to a specific parent page?
A list of child pages to an ancestor. The ancestor being page ID 44258.
Thanks
Melanie
In that case, I think you'd do this:
add_filter( 'generate_header_element_display', function( $display, $element_id ) {
$children = get_children( array( 'post_parent' => 44258 ) );
if ( 45458 === $element_id && ! is_empty( $children ) && is_singular( $children ) ) {
$display = true;
}
return $display;
}, 10, 2 );