[Resolved] Change the Action-Page of the Navigation Search

Home Forums Support [Resolved] Change the Action-Page of the Navigation Search

Home Forums Support Change the Action-Page of the Navigation Search

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #647555
    Andreas

    I would like to change the page where the search results are displayed. So I have to change the page in the <form action=””> to a certain page. How can I do this in a proper way?

    GeneratePress 2.1.3
    #648037
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this:

    add_filter( 'generate_navigation_search_output', function() {
        return sprintf( // WPCS: XSS ok, sanitization ok.
            '<form method="get" class="search-form navigation-search" action="%1$s">
                <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
             </form>',
             esc_url( home_url( '/' ) ),
             esc_attr( get_search_query() ),
             esc_attr_x( 'Search', 'label', 'generatepress' )
        );
    } );

    Then change the form action to whatever you like πŸ™‚

    #648190
    Andreas

    thank you Tom. I created a child theme and put your code in the functions.php of the child theme. It seems to me, that it is implemented now, but the form doesn’t work in the way it should work.

    Maybe you could have a look at my website where you can see the source.

    #648574
    Tom
    Lead Developer
    Lead Developer

    How did you change the filter? How is it supposed to work?

    Let me know πŸ™‚

    #649568
    Andreas

    I changed it to this snippet:
    add_filter( ‘generate_navigation_search_output’, function() {
    return sprintf( // WPCS: XSS ok, sanitization ok.
    ‘<form method=”get” class=”search-form navigation-search” action=”/suchergebnisse/”>
    <input type=”search” class=”search-field” value=”%2$s” name=”s” title=”%3$s” />
    </form>’,
    esc_url( home_url( ‘/’ ) ),
    esc_attr( get_search_query() ),
    esc_attr_x( ‘Search’, ‘label’, ‘generatepress’ )
    );
    } );

    the goal is that after sending the search that the page “/suchergebnisse/” is called with the query param “q”. It should work like the search on the right at this page: https://www.beispiele.at/euribor/

    #649904
    Tom
    Lead Developer
    Lead Developer

    Try changing name="s" to name="q".

    I can’t really see why else it wouldn’t be working.

    #650895
    Andreas

    thank you for your help, now it works. I pasted the code once again and heureka, it works!

    Have a nice day!

    #650991
    Tom
    Lead Developer
    Lead Developer

    You’re welcome! You too πŸ™‚

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