WordPress页面链接伪静态添加.html后缀

2021年10月29日 / 龙哥见解 / 没有评论 / 1,510次

将下面代码添加主题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';
    }
}

添加后,需要到固定链接设置页面,重新保存一下固定链接设置,否则不会生效。