- This topic has 12 replies, 3 voices, and was last updated 5 months, 3 weeks ago by
Tina.
-
AuthorPosts
-
July 7, 2022 at 2:02 am #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!
July 7, 2022 at 4:02 am #2275887David
StaffCustomer SupportHi 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 );
July 7, 2022 at 4:15 am #2275899Damiaan van Vliet
Hi David, thanks for reply but also does not work. Odd. I will give you login details.
July 7, 2022 at 5:27 am #2275955David
StaffCustomer SupportI assume it is the Portfolio page ? If so the ID of that is
522
July 7, 2022 at 5:45 am #2275969Damiaan 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.
July 7, 2022 at 6:26 am #2275998David
StaffCustomer SupportIn your Element, does the Display Rules include the initial location ? ie. the Parent Page ?
July 7, 2022 at 6:45 am #2276019Damiaan 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!July 8, 2022 at 1:46 am #2276909Damiaan 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.July 8, 2022 at 2:01 am #2276935David
StaffCustomer SupportAwesome – glad to hear that!
April 3, 2023 at 2:50 am #2594268Tina
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?
April 3, 2023 at 5:01 am #2594413David
StaffCustomer SupportHi Tina,
glad to hear this worked for you.
I will get the doc updated to make that clearerApril 3, 2023 at 10:53 am #2595105David
StaffCustomer SupportDoc has been updated! Thanks for the suggestion
April 4, 2023 at 12:26 am #2595746Tina
Perfect, thanks David!
-
AuthorPosts
- You must be logged in to reply to this topic.