[Resolved] Display element on child pages

Home Forums Support [Resolved] Display element on child pages

Home Forums Support Display element on child pages

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2275787
    Damiaan van Vliet

    Good morning team,
    I’ve created a header element with different logo and I want to display it on a page and all child pages.
    Of course I can add the pages through display rules but there are a lot of pages.
    So I’ve tried the code from the article about “generate_element_display”. But it’s not working.
    Parent page ID = 522
    Element ID = 160
    Code I’ve tried:

    /* element different logo on page portfolio en sub pages */
    add_filter( 'generate_element_display', function( $display, $element_id ) {
        global $post;
        if ( 160 === $element_id && 522 == $post->post_parent ) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    Thanks!

    #2275887
    David
    Staff
    Customer Support

    Hi there,

    try:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        
        if ( is_page() && 160 === $element_id ) {
            global $post;
            if ( 552 == $post->post_parent ) {
                $display = true;
            }
        }
        return $display;
    
    }, 10, 2 );
    #2275899
    Damiaan van Vliet

    Hi David, thanks for reply but also does not work. Odd. I will give you login details.

    #2275955
    David
    Staff
    Customer Support

    I assume it is the Portfolio page ? If so the ID of that is 522

    #2275969
    Damiaan van Vliet

    Hi David,
    Indeed portfolio = 522 and element post ID is indeed different, 607.

    So I tried:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        global $post;
        if ( 607 === $element_id && 522 == $post->post_parent ) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    and tried:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        
        if ( is_page() && 607 === $element_id ) {
            global $post;
            if ( 522 == $post->post_parent ) {
                $display = true;
            }
        }
        return $display;
    
    }, 10, 2 );

    but both did not work.

    #2275998
    David
    Staff
    Customer Support

    In your Element, does the Display Rules include the initial location ? ie. the Parent Page ?

    #2276019
    Damiaan van Vliet

    Hi David, I tried it with and without an initial location but does not matter. I will try (should have done first) to disable all unnecessary plugins and test again and come back to you later. That will be tomorrow.
    Thanks for helping!

    #2276909
    Damiaan van Vliet

    David it works! Disabled all plug-ins (on the test site it were a lot) and cleared cache.
    So thanks again for help.

    #2276935
    David
    Staff
    Customer Support

    Awesome – glad to hear that!

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.