WordPress页面(单页)url链接添加.html后缀

追格官方小助手/ 2022年03月19日/ WordPress/ 浏览 1596

追格小程序小编之前写过一篇《为WordPress页面(单页)链接添加固定的父级目录》,文章中也介绍了添加html后缀问题,今天小编再发一篇页面url链接添加.html后缀教程。


WordPress单页面url链接是不能设置 .html 这种后缀,就算手动编辑固定链接,添加.html也会被转码为“-html”形式,我们先看看效果:


原链接:
https://www.zhuige.com/news


修改后:
https://www.zhuige.com/news.html


我们只需将下面代码放到当前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';
	}
}


然后进入WordPress后台设置固定链接中,重新保存一次设置即可生效。

发表评论

暂无评论,抢个沙发...

客服 工单