WordPress页面文件添加html后缀名
使用过wordpress的朋友都知道,wordpress可以选择好几种固定连接,一般来说,我们为了对搜索引擎友好,都会选择伪静态的固定连接。
将下面代码添加主题functions.php中即可。
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';
}
}
添加后,就生效了吗?当然没有,我们还需要到固定链接设置页面,重新保存一下固定链接设置,否则不会生效。
上述代码适合伪静态的固定链接形式使用,比如:
/%postname%.html
/%post_id%.html
效果如下:https://www.nanlou.net/about.html
上述的方法,还有一些瑕疵,后来本站采用Custom Permalink Editor插件实现对本站任意链接的自定义,SEO效果比较好。