城市简码_如何使用WordPress搜索简码在帖子中添加搜索表单

城市简码

Recently one of our regular users ask if there was an easy way to add the WordPress search form in your post or page content using a shortcode. Well, the answer to that question is Yes. In this article, we will show you how to add the WordPress search form in your post or page content by creating a WordPress search shortcode.

最近,我们的一位普通用户问是否有一种简单的方法可以使用简码在您的帖子或页面内容中添加WordPress搜索表单。 好吧,这个问题的答案是肯定的。 在本文中,我们将向您展示如何通过创建WordPress搜索简码在您的帖子或页面内容中添加WordPress搜索表单。

All you have to do is open your theme’s functions.php file or a site-specific plugin and paste the following code:

您所要做的就是打开主题的functions.php文件或特定站点的插件,然后粘贴以下代码:

add_shortcode('wpbsearch', 'get_search_form');

Then use the shortcode in your post/page content like so: [wpbsearch]

然后在您的帖子/页面内容中使用简码,如下所示: [wpbsearch]

This will display the default search form. If you want to display a custom search form, then you can do so like this:

这将显示默认的搜索表单。 如果要显示自定义搜索表单,则可以这样进行:


function wpbsearchform( $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_shortcode('wpbsearch', 'wpbsearchform');

We hope that article will help all those who wanted to create a search form shortcode in WordPress.

我们希望本文对所有希望在WordPress中创建搜索表单简码的人有所帮助。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-add-search-form-in-your-post-with-a-wordpress-search-shortcode/

城市简码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值