- This topic has 31 replies, 4 voices, and was last updated 1 year, 5 months ago by David.
-
AuthorPosts
-
May 3, 2022 at 12:40 pm #2208232Maxime
Hi,
I would like to use the elements to display a different header image depending the directory of my pages.
Example :
https://mywebsite.com/directory1/page-1
https://mywebsite.com/directory1/page-2
https://mywebsite.com/directory1/page-3>> The same element for all the directory /directory1/
https://mywebsite.com/directory2/page-a
https://mywebsite.com/directory2/page-b
https://mywebsite.com/directory2/page-c>> The same element for all the directory /directory2/
Curently in the display rules I chose “page” and pick each page one-by-one (I have hundreds)
>> Is it possible to use a regex that with my directory name?
Thank you for your help
May 3, 2022 at 1:29 pm #2208268LeoStaffCustomer SupportHi there,
You can use this filter for advanced display rules:
https://docs.generatepress.com/article/generate_element_display/You will need to find the correct conditional tag to use which is not related to the theme:
https://codex.wordpress.org/Conditional_TagsHope this helps 🙂
May 9, 2022 at 12:33 pm #2214525MaximeHi Leo,
Thank you, this solution seems to answer my need, but but it doesn’t work. Did I misunderstand something?
At the end of the function.php file in my child theme I added :
add_filter( 'generate_element_display', function( $display, $element_id ) { global $post; if ( 5281 === $element_id && ( is_page() && $post->post_parent == '3854' ) ) { $display = true; } return $display; }, 10, 2 );
5281 : My Element ID
3854 : My parent page ID (/directory1/ in my previous example)Thank you in advance
May 10, 2022 at 2:07 am #2214884DavidStaffCustomer SupportHi there,
what happens if you flip it on its head, and set the Element Display rules to display on ALL pages, and set a negative condition to make it false:
if ( 5281 === $element_id && !( is_page() && $post->post_parent == '3854' ) ) { $display = false; }
May 10, 2022 at 12:41 pm #2215586MaximeHi David,
I tried :
– I chose “All website” as display rule
– I set a negative condition :add_filter( 'generate_element_display', function( $display, $element_id ) { global $post; if ( 5281 === $element_id && !( is_page() && $post->post_parent == '3854' ) ) { $display = false; } return $display; }, 10, 2 );
>> The function don’t working because my header is displayed on all pages
Screenshot with my function (sorry back-office in french) : https://ibb.co/6bfZx5CMay 10, 2022 at 5:15 pm #2215710YingStaffCustomer SupportHi Maxime,
When using this PHP snippet, can you make sure the location of the element is set to blank?
add_filter( 'generate_element_display', function( $display, $element_id ) { global $post; if ( 5281 === $element_id && ( is_page() && $post->post_parent == '3854' ) ) { $display = true; } return $display; }, 10, 2 );
Check the screenshot below:
https://www.screencast.com/t/RGtiPYHpMay 14, 2022 at 2:09 pm #2219757MaximeHi Ying,
Yes I tried to setting empty or pick other elements (all websites, pages…). but nothing change.
May 15, 2022 at 5:10 am #2220021DavidStaffCustomer SupportI tested Yings latest version, with the Block Elements display rules set to ‘blank’ and it worked.
Can you double check the ID of the Element and the Post Parent ?
May 23, 2022 at 12:28 pm #2229977MaximeI double checked The IDs and I tried with another page and another element(with the corresponding IDs), but no change.
When I Publish/Update my element, I have the followgin message : https://ibb.co/C11Sgbb
Could this be an indication regarding this issue?May 23, 2022 at 4:37 pm #2230137YingStaffCustomer SupportAh I see, header element doesn’t allow publish without location.
Can you try using block element?
May 24, 2022 at 4:46 am #2230711MaximeI tried with a “block” type Element but it still doesn’t work : https://ibb.co/GsdrBND
if it’s easier for you, I can give you a temporary access to the website. Let me know.
May 24, 2022 at 5:25 am #2230759DavidStaffCustomer SupportSend us a temporary admin login and we can take a look.
You can share the login details in the Private Information field.May 24, 2022 at 6:23 am #2230856MaximeThank you, I shared the access
May 24, 2022 at 7:08 am #2230903DavidStaffCustomer SupportOk – first thing i notice is the GP Premium version is only
1.12
– which is really out of data and thegenerate_element_display
filter wasn’t added until version2.0
.Is it possible to update the plugin ?
May 24, 2022 at 7:29 am #2230922MaximeOh yes,I updated the plugin with the version 2.1.2
-
AuthorPosts
- You must be logged in to reply to this topic.