从Wordpress的摘录中剥离标签是不起作用的


stripping tags from excerpt in Wordpress is not working

我正在使用这个片段

<a href='<?php the_permalink() ?>' title='<?php echo strip_tags(the_excerpt()); ?>

我打算删除所有ellipses<p>标签以及其他shortcodeslinks,但这根本不起作用。

如果我悬停在锚点上,我仍然可以看到摘录中的<p>,以及其他标签和url链接。我做错了什么?我必须做些什么才能让它发挥作用?

您需要的是get_the_excerpt():

<a href='<?php the_permalink() ?>' title='<?php echo strip_tags( get_the_excerpt() ); ?>'>

然而,它可能不会去掉省略号(…),因为它们是HTML实体,而不是标签。

这是因为_except()立即输出摘录。您需要get_the_except(),它将它作为一个可以处理的字符串返回(http://codex.wordpress.org/Function_Reference/get_the_excerpt)。

您也可以使用wp_filter_nohtml_kses()(http://codex.wordpress.org/Function_Reference/wp_filter_nohtml_kses)

类似于:

$title = wp_filter_nohtml_kses(get_the_excerpt());