I want to change the default name 's' to something else for the search widget of wordpress. So, basically I will need to change the widget template and the handler that reads the GET input. Can you please help me finding those two place quickly please? Thanks.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
This is the solution I've used, where 'q' is the name of the search field:
function my_query_vars( $public_query_vars ) {
if ( isset( $_GET['q'] ) && ! empty( $_GET['q'] ) ) {
$_GET['s'] = $_GET['q'];
}
return $public_query_vars;
}
add_filter( 'query_vars', 'my_query_vars' );
回答2:
Searched on google "get search form wordpress"
taken from here: http://codex.wordpress.org/Function_Reference/get_search_form
Drop this function in your theme's functions.php
function my_search_form( $form ) {
$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<div><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') .'" />
</div>
</form>';
return $form;
}
add_filter( 'get_search_form', 'my_search_form' );