WordPress页面链接添加.html后缀
发布:WordPress教程网 发布时间:
2022-10-14 游览次数:131次
默认WordPress页面不能实现伪静态链接,比如:http://www.wpcn.net/2.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' )
$string = trailingslashit($string);
return $string;
}
add_filter('user_trailingslashit', 'nice_trailingslashit', 10, 2);
排除页面文件,否则页面链接.html后面也会自动加上斜杠。
本文版权归原作者所有,转载请注明原文来源出处, WordPress教程网 感谢您的支持!
本文链接: http://www.wpcn.net/39.html
推荐内容
热点阅读
相关内容
- WordPress手动升级详细步骤
- WordPress手动安全升级
- WordPress后台无插件显示文章和分类ID
- WordPress优化:wp_head和remove_action函数
- query_posts函数把你的wordpress博客变成CMS
- Bootstrap替换WordPress的get_search_form()…
- WordPress 函数:register_sidebar()创建主…
- wp_list_comments()使用回调函数自定义评论…
- WordPress过滤器(Filters):apply_filters和…
- WordPress函数:comments_template(加载评…
- WordPress函数:comment_form( )个性化评论…
- 无处不在的WordPress的主循环
- WordPress 函数do_action()详解和应用举例
- WordPress函数:add_menu_page()后台添加顶…
- WordPress函数:add_theme_page()后台添加设…
- WordPress函数:add_submenu_page()后台为顶…
- WordPress 函数:get_template_part()调用你…
- WordPress函数:load_theme_textdomain()(…
- WordPress 3D旋转彩色标签云
- WordPress文本小工具运行PHP
- WordPress无插件实现主题彩色标签云的N种方…
- WordPress函数:wp_tag_cloud(标签云)详解和…
- WordPress函数:register post type (自定义…
- WordPress使用register_post_type 函数创建…