WordPress默认搜索链接是这样的:https://域名/?s=内容
https://www.fzxx.xyz/?s=wordpress
虽然没有什么问题,但为了防止机器人刷关键词或者想美化链接,可以将它修改为
https://www.fzxx.xyz/search/wordpress
只需要将下面代码添加到当前主题的 functions.php 文件即可:
//搜索结果的链接修改
function redirect_search() {
if (is_search() && !empty($_GET['s'])) {
wp_redirect(home_url("/search/").urlencode(get_query_var('s')));
exit();
}
}
add_action('template_redirect', 'redirect_search' );
注:需要主机支持伪静态
风之暇想博客
评论前必须登录!
立即登录 注册