Archived topic
Change the Action-Page of the Navigation Search
7 replies · Started by Andreas on August 14, 2018
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?
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 :)
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.
How did you change the filter? How is it supposed to work?
Let me know :)
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/
Try changing name="s" to name="q".
I can't really see why else it wouldn't be working.
thank you for your help, now it works. I pasted the code once again and heureka, it works!
Have a nice day!
You're welcome! You too :)