Site logo

Archived topic

Display element on child pages

12 replies · Started by Damiaan van Vliet on July 7, 2022

Viewing posts 1–13 of 13

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!

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 );

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

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

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.

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

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!

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

Awesome - glad to hear that!

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?

Hi Tina,

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

Doc has been updated! Thanks for the suggestion

Perfect, thanks David!

This archived topic is closed to new replies.