添加html后缀的WordPress页面链接新手教程

2021-08-01 0 543

带 html 后缀的 WordPress 页面链接新手教程

默认的 WordPress 页面无法实现伪静态链接,例如:https://www.huizhanii.com/aboutus.html,如果你手动添加” “。HTML“链接,它会自动转换为“-HTML”,但一般 WordPress 会有相应的插件来帮助你实现你能想到的所有功能。因为它可以用插件实现,所以也可以直接将插件中的代码集成到主题中。代码是从数据库中提取的。Htmlonpages 插件,您可以将以下代码添加到主题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', 'nice_trailingslashit', 10, 2);

排除页面文件,否则页面链接.html 后面也会自动加上斜杠。

转载请注明:汇站网 » 添加 html 后缀的 WordPress 页面链接新手教程

收藏 (0)

微信支付 微信扫一扫

支付宝支付 支付宝扫一扫

点赞 (0)

站长资源下载中心-找源码上汇站

常见问题
  • 如果付款后没有弹出下载页面,多刷新几下,有问题联系客服!
查看详情
  • 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
查看详情

相关文章

联系官方客服

为您解决烦忧 - 24小时在线 专业服务