开门见山了哈,分享一下为Wordpress文章链接添加.html后缀的方法,也方便自己作个记录!
方法相对来说比较简单,代码照搬即可,不需要进行修改的操作。原理也是简单的,就是重写了URL地址!
第一步:将以下代码复制后,添加到所使用主题的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'; } }
第二步:登陆Wordpress后台 -> 设置 -> 固定链接 -> 自定义结构 后面的框中输入以下两种固定链接结构的其中一种,然后保存更改即可!
1. /%postname%.html 2. /%post_id%.html
如下图所示:
赶紧去试试吧!
本文作者为马克江山,转载请注明。