自定义搜索表单文本输入字段名称 [英] Customize Search Form Text Input Field Name

查看:63
本文介绍了自定义搜索表单文本输入字段名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将wordpress的搜索小部件的默认名称's'更改为其他名称.因此,基本上,我将需要更改小部件模板和读取GET输入的处理程序.您能帮我快速找到这两个地方吗?谢谢.

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.

推荐答案

这是我使用的解决方案,其中"q"是搜索字段的名称:

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' );

这篇关于自定义搜索表单文本输入字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆