介紹3 給niwordpress增加.html綴:
1簡單修改固定鏈接
wordpress自帶固定鏈接改變鏈接式格式沒寫能給ni頁面訪問帶困難鏈接特殊符號 空格包含文固定鏈接格式:/%postname%.html 文行wo格式/archives/%post_id%.html
2插件實現
單獨頁面添加.html綴
安裝:.html on PAGES 插件實現啟用插件需任何設置
類及頁面同添加.html綴
安裝:.html in category and page url 插件啟用插件需要插件設置頁面保存設置
需要注意啟用插件需要臺固定鏈接設置重新保存設置否則跳404頁面功先刪除空間根目錄.htaccess文件保存自新
另外安裝插件能造志頁翻頁錯誤…..
3.既插件代碼
下面代碼添加主題function即
- // 頁面鏈接添加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' )
- $string = trailingslashit($string);
- return $string;
- }
- add_filter('user_trailingslashit', 'nice_trailingslashit', 10, 2);
排除頁面文件否則頁面鏈接.html面自加斜杠。
新聞熱點
疑難解答
圖片精選