×

目录加斜杠

WordPress给文章链接后缀html及分类目录链接添加斜杠/的方法

litang litang 发表于2024-05-15 22:00:40 浏览225 评论0

抢沙发发表评论

默认WordPress文章页面后缀链接没有html,如https://blog.seo178.com/googleseo ,它再没改动之前文章页面链接https://blog.seo178.com/googleseo

只需要在当前模板目录下functions.php文件中添加代码即刻添加后缀,下面是具体代码片段

WordPress给添加文章后缀html代码

  1. /%postname%.html
  2. /%post_id%.html

1.需要到固定链接设置页面,重新保存一下固定链接设置,否则不会生效。下面是代码

2.页面链接添加html后缀

  1. add_action('init','html_page_permalink',-1);
  2. function html_page_permalink(){
  3. global $wp_rewrite;
  4. if(!strpos($wp_rewrite->get_page_permastruct(),'.html')){
  5. $wp_rewrite->page_structure = $wp_rewrite->page_structure .'.html';
  6. }
  7. }

给WordPress分类目录和tag分类目录添加斜杠/

下面是排除页面文件代码,否则页面链接.html后面也会自动加上斜杠。

  1. function nice_trailingslashit($string, $type_of_url){
  2. if( $type_of_url !='single'&& $type_of_url !='page')
  3. $string = trailingslashit($string);
  4. return $string;
  5. }
  6. add_filter('user_trailingslashit','nice_trailingslashit',10,2);

点点赞赏,手留余香!