设为首页 - 加入收藏
广告 1000x90
您的当前位置:主页 > 网站运营 > 正文

WordPress实现全站.html链接

来源:网络分享 编辑:引流技巧 时间:2026-01-27

大家一般都知道通过后台自定义固定连接,可以实现文章链接以.html结尾,相比大家也发现了一个小小的现象,wordpress后台设置的自定义固定链接却没有办法在页面上实现,今天南京SEO就告诉大家一个好方法实现全部页面以.html结尾。

add_action('init', 'html_page_permalink', -1);

register_activation_hook(__FILE__, 'barley_active');

register_deactivation_hook(__FILE__, 'barley_deactive');

function html_page_permalink() {

    global $wp_rewrite;

    if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){

        $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';

    } 

}

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

function no_page_slash($string, $type){

    global $wp_rewrite;

    if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){

        return untrailingslashit($string);

    } else {

        return $string;

    }

}

function barley_active() {

    global $wp_rewrite;

    if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){

        $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';

    }

    $wp_rewrite->flush_rules();

}

function barley_deactive() {

    global $wp_rewrite;

    $wp_rewrite->page_structure = str_replace(".html","",$wp_rewrite->page_structure);

    $wp_rewrite->flush_rules();

}

  将这段代码放在主题文件的functions.php里面,再去后台设置固定链接为为文章名.html或者是id.html,再更新一次,去前台看看是不是实现了你想要的效果呢!

相关推荐:

栏目分类

微商引流技巧网 www.yinliujiqiao.com 联系QQ:1716014443 邮箱:1716014443@qq.com

Copyright © 2019-2024 强大传媒 吉ICP备19000289号-9 网站地图 rss地图

Top