有一种已知的工作方法可以替换整个WordPress搜索字段,包括占位符文本。
function html5_search_form( $form ) {
$form = '<section class="search"><form role="search" method="get" id="search-form" action="' . home_url( '/' ) . '" ><label class="screen-reader-text" for="s">' . __('', 'domain') . '</label><input type="search" value="' . get_search_query() . '" name="s" id="s" placeholder="Search website" /><input type="submit" id="searchsubmit" value="'. esc_attr__('Go', 'domain') .'" /></form></section>';
return $form;}
add_filter( 'get_search_form', 'html5_search_form' );
如何在不更改表单代码和语言文件的情况下仅替换占位符默认文本?
答案 0 :(得分:0)
将其放入主题功能文件中:
function html5_search_form( $form ) {
$form = '<section class="search"><form role="search" method="get" id="search-form" action="' . home_url( '/' ) . '" >
<label class="screen-reader-text" for="s">' . __('', 'domain') . '</label>
<input type="search" value="' . get_search_query() . '" name="s" id="s" placeholder="Search website" />
<input type="submit" id="searchsubmit" value="'. esc_attr__('Go', 'domain') .'" />
</form></section>';
return $form;
}
add_filter( 'get_search_form', 'html5_search_form' );