[Resolved] Elements block hook location for specific url

Home Forums Support Elements block hook location for specific url

  • This topic has 5 replies, 2 voices, and was last updated 1 week ago by David.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1668988
    Oleksandr

    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”

    #1669018
    David
    Staff
    Customer Support

    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.

    #1669269
    Oleksandr

    Maybe I misunderstood you, but I mean this setting:
    http://joxi.ru/DmBPNLqU43b4MA

    #1669316
    David
    Staff
    Customer Support

    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.

    #1669626
    Oleksandr

    Ok, I understand. It’s what I need. Thank you!

    #1669960
    David
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.