删除摘录的所有格式标签

时间:2014-11-05 03:08:55

标签: php wordpress meta

底部代码的作者声明他使用了_excerpt_rss(),因为它"剥离了所有格式化标签"。我的问题是下面的两个代码"删除所有格式标签" ?下面两个代码有什么区别?您建议使用哪种?

<meta name="description" content="<?php echo strip_tags(get_the_excerpt($post->ID)); ?>" />

versus

<meta name="description" content="<?php the_excerpt_rss(); ?>" />

1 个答案:

答案 0 :(得分:1)

默认情况下,the_excerpt_rss()执行剥离HTML标记,解析编号URL脚注的链接。为了让它实际去掉标签,你必须将2传递给参数$ encode_html(见http://codex.wordpress.org/Template_Tags/the_excerpt_rss):

  

$ encode_html
  (整数)定义html标记过滤和特殊字符(例如'&amp;')编码。选项包括:
  0 - (默认)解析编号为“url脚注”的链接   1 - 通过PHP函数htmlspecialchars()过滤,但也将cut设置为0,因此不建议使用&gt;使用切割参数时。
  2 - 剥离html标签,并替换'&amp;'与HTML实体等效(&amp;)。这是&gt;时的默认值使用cut参数。

我可能会依赖PHP strip_tags(),因为the_excerpt_rss()打算用于RSS提要,所以strip_tags()对我来说似乎更清晰。