如何在WordPress页面URL添加.html后缀?

  一般WordPress默认页面是不能实现伪静态链接的,比如:https://www.wpmee.com/5278.html,想要实现该功能,万能的WordPress会帮助大家实现,今天我们就一起看看如何在WordPress页面URL添加.html后缀?

如何在WordPress页面URL添加.html后缀? (https://www.wp-admin.cn/) WordPress使用教程 第1张

  WordPress插件可以帮助大家实现.html后缀,可以直接将插件中的代码集成到主题中,代码提取自.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

  另外,还需要将该文中的代码修改为:

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

相关推荐

发表回复

房先生
我们将24小时内回复。
2024-05-02 21:21:07
您好,有任何疑问请与我们联系!
您的工单我们已经收到,我们将会尽快跟您联系!
[加我微信]
chaoneo
注:点击复制微信号并打开微信APP,添加好友后进行聊天。
[电话联系]
13585372227
[电子邮件]
chaoneo@163.com
取消

选择聊天工具: