Archived topic
Elements block hook location for specific url
5 replies · Started by Oleksandr on February 23, 2021
Hi!
How I can customize the location for a specific URL using a mask or URL which contains a specific string (for Elements type "block hook")?
E.g. I need to show my custom footer (made with Elements) only for those pages, which have in their ULR word "London"
Hi there,
First you don't set a Display Location in the Block Element
Then use the generate_block_element_display filter to set it to display true if the correct conditions are met so something like this:
add_filter( 'generate_block_element_display', function( $display, $element_id ) {
if ( 123 === $element_id && strpos($_SERVER['REQUEST_URI'], 'london') !== false ) {
$display = true;
}
return $display;
}, 10, 2 );
The 123 in the code is the Elements ID - which will need to be changed to match your Block Elements ID.
Maybe I misunderstood you, but I mean this setting:
http://joxi.ru/DmBPNLqU43b4MA
If you want to use the Display Rules in the Element then you will need to add each page, post, archive that you want it to be displayed on... there is no Location URL Contains option... the only way to do this is using the code i provided.
Ok, I understand. It's what I need. Thank you!
You're welcome