狠狠网/色综合久久久久综合体桃花网/日本护士三aaaaaa/久久久久久综合一区中文字幕

或者

WordPress實現全站.html鏈接

作者:微笑 瀏覽:278 發布時間:2017-07-27
分享 評論 0

大家一般都知道通過后臺自定義固定連接,可以實現文章鏈接以.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,再更新一次,去前臺看看是不是實現了你想要的效果呢!