wordpress 页面默认不能实现伪静态链接,手动在链接中添加 “.html” ,会自动转码为 “-html” ,但万能的 WordPress,你能想到的功能都会有相应的插件帮你实现。
页面文件添加html后缀名教程:
将下面代码添加主题 functions.php 中即可:
<span class="token comment">// 页面链接添加html后缀</span>
<span class="token function">add_action</span><span class="token punctuation">(</span><span class="token single-quoted-string string">'init'</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'html_page_permalink'</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">function</span> <span class="token function">html_page_permalink</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{
</span>
<span class="token keyword">global</span> <span class="token variable">$wp_rewrite</span><span class="token punctuation">;</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token operator">!</span><span class="token function">strpos</span><span class="token punctuation">(</span><span class="token variable">$wp_rewrite</span><span class="token operator">-</span><span class="token operator">></span><span class="token function">get_page_permastruct</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token single-quoted-string string">'.html'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{
</span>
<span class="token variable">$wp_rewrite</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">page_structure</span> <span class="token operator">=</span> <span class="token variable">$wp_rewrite</span><span class="token operator">-</span><span class="token operator">></span><span class="token property">page_structure</span> <span class="token punctuation">.</span> <span class="token single-quoted-string string">'.html'</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
注意,添加完代码后,一定记得去后台把所有页面文件全部重新发布一遍!否则无法访问