[Resolved] Display element on child pages

Home Forums Support [Resolved] Display element on child pages

Home Forums Support Display element on child pages

  • This topic has 12 replies, 3 voices, and was last updated 1 year ago by Tina.
Viewing 13 posts - 1 through 13 (of 13 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!

    #2594268
    Tina

    Hi David, I landed here by doing a search, I had the same problem but for me your comment “does the Display Rules include the initial location” did the trick – as soon as I selected the parent page as initial location, the filter started working. perhaps you could consider adding a note to that effect here for clarity?

    #2594413
    David
    Staff
    Customer Support

    Hi Tina,

    glad to hear this worked for you.
    I will get the doc updated to make that clearer

    #2595105
    David
    Staff
    Customer Support

    Doc has been updated! Thanks for the suggestion

    #2595746
    Tina

    Perfect, thanks David!

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