我们都知道,WordPress搜索结果页面的默认链接是这样的:domain/?s=[search query],例如
https://www.wpdaxue.com/?s=wordpress入门 |
https://www.wpdaxue.com/?s=wordpress入门
这样的链接实在是有些混乱,你可以将它修改为
https://www.wpdaxue.com/search/wordpress入门 |
https://www.wpdaxue.com/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' ); |
//修改搜索结果的链接
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' );
注:需要主机支持伪静态(即支持 rewrite)
来源:
https://www.wpdaxue.com/redirect-wordpress-searches.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32775.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57