wordpress插件引入html,WordPress插件给页面URL固定链接添加伪静态.html后缀

在WordPress中,尽管你把固定链接设置成 /%postname%.html这种形式,也只能给文章的URL添加 .html 后缀,其余页面的URL都是没有 .html 后缀的。这次我们讲讲如何给WordPress博客的页面URL添加.html后缀。

使用插件:

如果想给页面URL添加 .html 后缀,可以使用使用这款插件:

资源下载框: 出现问题了,这里应该是一个资源下载框!当你看见此提示,是因为由于网站改版,下载方式变更,此处已无法显示。此资源原始ID:106

虽然更换了下载方式,但资源并未删除,您可以在文章评论留言提醒我,逍遥将在第一时间补上此下载资源的链接。非常您的支持!点击立即留言

如果想给页面URL添加 .php 后缀,可以使用使用这款插件:

资源下载框: 出现问题了,这里应该是一个资源下载框!当你看见此提示,是因为由于网站改版,下载方式变更,此处已无法显示。此资源原始ID:107

虽然更换了下载方式,但资源并未删除,您可以在文章评论留言提醒我,逍遥将在第一时间补上此下载资源的链接。非常您的支持!点击立即留言

52b542d98385856e36b9701f6cb1afcd.png

特定页面不添加后缀:

.html on PAGES 插件会给所有页面都添加上.html后缀,但是问题又来了,如果我们不想给 sitemap 页面URL添加 .html 后缀,保持 /sitemap,而不是 /sitemap.html,那么怎么办呢?如果你有这个需求,可以用文本编辑器打开插件目录下的html-on-pages.php,查找:

add_filter('user_trailingslashit', 'no_page_slash',66,2);

将其替换成:

add_filter('page_link', 'blog_permalinks_page_link', 10, 2);

function blog_permalinks_page_link($permalink, $page) {

$pos = strpos($permalink, "/sitemap.html");

if ($pos !== false) {

$permalink = str_replace("/sitemap.html", "/sitemap", $permalink);

}

return $permalink;

}

add_filter('user_trailingslashit', 'no_page_slash', 66, 2);

接着查找:

function html_page_permalink() {

将其替换成:

function html_page_permalink() {

$string = $_SERVER['REQUEST_URI'];

$pos = strpos($string, "/sitemap.html");

if ($pos !== false) {

switch_to_blog(1); //We are using WPMU if you are not you won't need this line.

wp_redirect(get_option('home') . str_replace('/sitemap.html', '/sitemap', $string), 301);

exit();

}

else {

$pos = strpos($string, "/sitemap");

if ($pos !== false) {

$_SERVER['REQUEST_URI'] = str_replace("/sitemap", "/sitemap.html", $string);

global $wp;

$wp->parse_request();

}

}

好了,修改就到此结束。你可以根据把代码中的 sitemap 改成你的页面别名。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值