冠富商务通中文社区

 找回密码
 立即注册
查看: 8|回复: 0
打印 上一主题 下一主题
收起左侧

WordPress页面链接添加.html后缀

[复制链接]
跳转到指定楼层
楼主
发表于 2017-1-6 00:36:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
默认WordPress页面不能实现伪静态链接,比如:http://zmingcx.com/begin.html,手动在链接中添加“.html”,会自动转码为"-html",但万能的WordPress,你能想到的功能都会有相应的插件帮你实现。
将下面代码添加主题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';
}
}
添加后,需要到固定链接设置页面,重新保存一下固定链接设置,否则不会生效。
上述代码适合伪静态的固定链接形式使用,比如:
/%postname%.html
/%post_id%.html
另外,如果同时使用了“给WordPress分类目录和页面添加斜杠”一文中的代码,还需要将该文中的代码修改为:
// 添加斜杠
function nice_trailingslashit($string, $type_of_url) {
if ( $type_of_url != 'single' && $type_of_url != 'page' )
$string = trailingslashit($string);
return $string;
}
add_filter('user_trailingslashit', 'nice_trailingslashit', 10, 2);
排除页面文件,否则页面链接.html后面也会自动加上斜杠。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|关于我们|申请友链|Archiver|手机版|拘留所|冠富商务通

GMT+8, 2025-5-19 14:17 , Processed in 0.099006 second(s), 15 queries , Wincache On.

Powered by HCMS Version 2.0

© 2008-05-14 guanfu.net.cn

快速回复 返回顶部 返回列表