WordPress文章摘要支持HTML标签 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【meiwen.anslib.com - 电脑资料】

  在进行 WordPress 主题开发的时候,使用 the_excerpt() 调用出来的文章摘要是不支持 HTML 标签的,但我们还是可以通过 filter 的方法来让文章摘要支持 HTML 标签,可以在主题的 functions.php 里加入以下代码,

WordPress文章摘要支持HTML标签

<span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">add_filter</span><span class="sh_symbol">(</span><span style="color: rgb(255, 0, 255); font-weight: normal; font-style. normal; " class="sh_string">'the_excerpt'</span><span class="sh_symbol">,</span> <span style="color: rgb(255, 0, 255); font-weight: normal; font-style. normal; " class="sh_string">'excerpt_force_balance_tags'</span><span class="sh_symbol">);</span> 
<span style="color: rgb(165, 42, 42); font-weight: normal; font-style. normal; " class="sh_keyword">function</span> <span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">excerpt_force_balance_tags</span> <span class="sh_symbol">(</span>$output<span class="sh_symbol">)</span> <span class="sh_cbracket">{</span> 
    <span style="color: rgb(165, 42, 42); font-weight: normal; font-style. normal; " class="sh_keyword">return</span> $output <span class="sh_symbol">=</span> <span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">force_balance_tags</span><span class="sh_symbol">(</span>$output<span class="sh_symbol">);;</span> 
<span class="sh_cbracket">}</span> 

  如果真的需要让文章摘要支持 HTML 标签,建议加上条件判断,不要在 RSS 中将文章摘要里的 HTML 代码展示出来,

电脑资料

WordPress文章摘要支持HTML标签》(http://meiwen.anslib.com)。

最新文章