「Wor代码提取自.html on PAGES插件,将下面代码添加主题functions.php中即可。dPress教程」纯代码给WordPress页面链接添加.html后缀实现方法
默认WordPress页面不能实现伪静态链接,比如:https://wpfans.net/sitemaps.html,手动在链接中添加“.html”,会自动转码为”-html”,但万能的WordPress,你能想到的功能都会有相应的插件帮你实现。今天不说插件实现方法,毕竟能少装插件就少装,下面就说说代码实现方案。
本代码提取自.html on PAGES插件,将下面代码添加主题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
使用。