前言
默认状态下WordPress是不可以给页面URL结尾添加“.html”实现伪静态的(部分主题除外),就像这样:
https://chenjianhao.com/about.html
就算你在编辑页面自定义链接中改为“about.html”也会自动改为“about-html”,就像这样:
https://chenjianhao.com/about-html
那么我们该怎么实现这一功能呢?
实现方法
1、在“function.php”文件结尾添加以下代码,并保存。
添加方法:修改functions.php文件
//页面链接添加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';
}
}
2、进入后台“设置>固定链接”,修改以下设置。
修改后并保存设置,然后刷新页面,即可看到页面会带上“.html”结尾。
此代码在 适合伪静态的固定链接形式使用(即页面与文章页等),例如以下链接:
/%postname%.html
/%post_id%.html
如有问题请在下方进行评论留言,谢谢。
总结非常好,学习了!
谢谢