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

WordPress 页面链接添加html后缀

发布时间:2020-05-25 03:02:00 所属栏目:CMS系统 来源:互联网
导读:默认WordPress页面不能实现伪静态链接,比如:https://www.22vd.com/aboutus.html,手动在链接中添加“.html”,会自动转码为-html,但万能的WordPress,你

下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。脚本之家小编现在分享给大家,也给大家做个参考。

默认 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 后面也会自动加上斜杠。

以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

(编辑:安卓应用网)

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

    推荐文章
      热点阅读