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

WP技巧9年前 (2016)发布 thec
3,596 00

WordPress为页面链接添加.html伪静态后缀
wordpress文章伪静态直接后台设置固定链接就行了,但是页面却没有设置项。
我们可以使用代码解决这个问题。下面代码加入主题function.php 文件中,你也可以如我前几天介绍的文章中添加自定义功能小插件来使用这个功能。

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

然后重新保存一下固定链接设置,所有的页面地址就都有.html后缀了。
但是如果你还需要对分类目录或者页面添加后缀斜杠 / 的话最好参考
https://im.acirno.com/1171.html
避免一些问题。

© 版权声明

相关文章