[Support request] Display Elements via filters

Home Forums Support [Support request] Display Elements via filters

Home Forums Support Display Elements via filters

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #763252
    melanie

    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 );
    #763370
    Tom
    Lead Developer
    Lead Developer

    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?

    #766136
    melanie

    A list of child pages to an ancestor. The ancestor being page ID 44258.

    Thanks
    Melanie

    #766340
    Tom
    Lead Developer
    Lead Developer

    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 );
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.