加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

WordPress 页面链接添加html后缀

发布时间:2020-12-14 14:24:55 所属栏目:wordpress 来源:网络整理
导读:由站长 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。 默认 wordpress 页面不能实现伪静态链接,比如:https://www.22vd.com/aboutus.html,手动在链接中添加“.html”,会自动转码为"-html",但万能的 Word

以下代码由PHP站长网 52php.cn收集自互联网现在PHP站长网小编把它分享给大家,仅供参考

默认 wordpress 页面不能实现伪静态链接,比如:https://www.22vd.com/aboutus.html,手动在链接中添加“.html”,会自动转码为"-html",但万能的 WordPress,你能想到的功能都会有相应的插件帮你实现。既然用插件可以实现,直接将插件中的代码集成到主题中同样也可以,代码提取自.html on PAGES 插件,将下面代码添加主题 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' && $type_of_url != 'single_paged' )

$string = trailingslashit($string);

return $string;

}

add_filter('user_trailingslashit','nice_trailingslashit',10,2);

则还需要将该代码修改为:

// 添加斜杠

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',2);

排除页面文件,否则页面链接.html 后面也会自动加上斜杠。

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读