WordPress页面链接伪静态添加.html后缀

2021年10 月29日 / 网站源码 / 没有评论 / 1,957次

将下面代码添加主题functions.php中即可。

  1. // 页面链接添加html后缀
  2. add_action('init', 'html_page_permalink', -1);
  3. function html_page_permalink() {
  4.     global $wp_rewrite;
  5.     if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
  6.         $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
  7.     }
  8. }

添加后,需要到固定链接设置页面,重新保存一下固定链接设置,否则不会生效。