wordpress是可以自定义链接的,从何让网站链接更符合SEO规范,wordpress默认伪静态分类页链接后什么都没有,但分类我们知道更像是一个目录,而目录一般都是用”/”斜杠表示。所以我们的目标是将:https://www.threeke.com/wordpress这样的链接替换成https://www.threeke.com/wordpress/
设置》固定链接》自定义规则结构
/%category%/%post_id%.html
当设置伪静态规则后独立页面后缀并没有以.html结尾,也需要优化
1、链接优化开启伪静态,Nginx规则
location / { try_files $uri $uri/ /index.php?$args; } rewrite /wp-admin$ $scheme://$host$uri/ permanent;
2、给分类目录加上斜杠
// 添加斜杠 function nice_trailingslashit($string, $type_of_url) { if ( $type_of_url != 'single' && $type_of_url != 'page' ) $string = trailingslashit($string); return $string; } add_filter('user_trailingslashit', 'nice_trailingslashit', 10, 2);
3、页面链接加上html后缀
// 页面链接添加html后缀 add_action('init', 'html_page_permalink', -1); function html_page_permalink() { global $wp_rewrite; if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){ $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html'; } }
代码添加至主题目录functions.php里即可
未经允许不得转载:网站建设教程 » wordpress链接优化,给分类目录加上斜杠,页面链接加上html后缀