带 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
分类目录和页面添加斜杠”一文中的代码,还需要将该文中的代码修改为:
则还需要将该代码修改为:
排除页面文件,否则页面链接.html
后面也会自动加上斜杠。
转载请注明:汇站网 » 添加 html
后缀的 WordPress
页面链接新手教程