[Resolved] Use specific element when particular query appears in URL

Home Forums Support [Resolved] Use specific element when particular query appears in URL

Home Forums Support Use specific element when particular query appears in URL

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2228232
    Matt

    Hello,

    I’m building a section of my site that requires its own search tool, separate from the main site search. I’m using WP Extended Search plugin to generate a custom search form.

    What I would like is for the search results page from the custom search form to be visually different to the main site search results page.

    WP Extended Search adds the query string ‘wpessid=42610’ to all the search results. I was wondering whether it was possible to trigger specific elements when this query appears in the URL?

    #2228277
    David
    Staff
    Customer Support

    Hi there,

    there is the generate_element_display filter that you can use to set your own display conditions for an Element.

    https://docs.generatepress.com/article/generate_element_display/

    So you can try this:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 99 === $element_id && isset( $_GET['your-url-param'] ) ) {
            $display = true;
        }
    
        return $display;
    }, 10, 2 );

    Where 99 is the ID of the Block Element.

    #2228284
    Matt

    Fabulous! Thanks, that’s working great.

    Since I have elements loading generally for the search results page, is there a similar function that excludes certain elements for particular URL parameters?

    #2228285
    David
    Staff
    Customer Support

    Awesome – you can add another snippet like the above and change $display = true; to $display = false;

    #2228287
    Matt

    Hah! Yep, that makes sense.

    Wonderful support as always. Many, many thanks!!!

    #2228292
    David
    Staff
    Customer Support

    You’re welcome 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.