- This topic has 10 replies, 4 voices, and was last updated 4 minutes ago by
Maxime.
-
AuthorPosts
-
May 3, 2022 at 12:40 pm #2208232
Maxime
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 #2208268Leo
StaffCustomer 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 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/May 9, 2022 at 12:33 pm #2214525Maxime
Hi 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 #2214884David
StaffCustomer 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; }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/May 10, 2022 at 12:41 pm #2215586Maxime
Hi 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 #2215710Ying
StaffCustomer 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 #2219757Maxime
Hi Ying,
Yes I tried to setting empty or pick other elements (all websites, pages…). but nothing change.
May 15, 2022 at 5:10 am #2220021David
StaffCustomer 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 ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/May 23, 2022 at 12:28 pm #2229977Maxime
I 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 #2230137Ying
StaffCustomer SupportAh I see, header element doesn’t allow publish without location.
Can you try using block element?
May 24, 2022 at 4:46 am #2230711Maxime
I 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.
-
AuthorPosts
- You must be logged in to reply to this topic.