表单操作-自定义网址

我的wordpress主题中有一个搜索表单。我想要搜索结果中的自定义网址。

我的源代码:

<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<input type="text" name="s" id="s" onblur="if (value =='') {value = 'Search'}" onfocus="if (value == 'Search') {value =''}" value="Search" />
<input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( '', 'themevb' ); ?>" />
</form>

我的实际搜索网址:

http://www.example.com/?s=keyword&submit=

我需要这个网址:

http://www.example.com/web/keyword

#1


最简单的解决方案是, 将该脚本放入队列, 或者仅放在搜索表单下方, 它将导航到自定义搜索页面。

<script>
jQuery(function($){
    $( '#searchform' ).on( 'submit', function() {
        window.location = "http://www.example.com/web/" + encodeURIComponent( $(this).find( '#s' ).val() );
        return false;
    });
});
</script>

添加自定义重写规则, 请记住通过访问”管理”部分中的”设置”->”永久链接”标签来刷新规则。

add_rewrite_rule( 'web/(.+?)/?$', 'index.php?s=$matches[1]' );

来源:

https://www.srcmini02.com/67255.html

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?