@vladimir
To change the action of the search form in WordPress, you can use the get_search_form
filter hook in your theme's functions.php
file. Here's an example code snippet that demonstrates how to change the action URL to a custom URL:
1 2 3 4 5 6 7 8 9 10 |
function change_search_form_action( $form ) { $form = '<form role="search" method="get" id="searchform" action="http://example.com/custom-search-page/"> <label class="screen-reader-text" for="s">' . __('Search for:') . '</label> <input type="text" value="' . get_search_query() . '" name="s" id="s" /> <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" /> </form>'; return $form; } add_filter( 'get_search_form', 'change_search_form_action' ); |
In the above code, we use the get_search_form
filter hook to modify the HTML output of the search form. We replace the action
attribute of the <form>
element with our custom URL, which in this case is http://example.com/custom-search-page/
. You can replace this URL with your own custom search page URL.
After adding this code to your theme's functions.php
file, the search form in your WordPress site will use the new custom action URL that you specified.