默认WordPress页面不能实现伪静态链接,比如自建模板自带的网站地图页面别名为:sitemap.html,手动在链接中添加“.html”,会自动转码为”.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';
}
}
使用方法
1.把以上代码添加到添加主题functions.php中
2.添加后,需要到固定链接设置页面,重新保存一下固定链接设置,否则不会生效。(但是这样所有的自建页面都会带上.html后缀!)
提示:上述代码适合伪静态的固定链接形式使用!
常用的伪静态固定链接加.html
- post-%post_id%.html
- /%post_id%.html