use*_*896 6 php wordpress strip strip-tags
我正在使用这个片段
<a href='<?php the_permalink() ?>' title='<?php echo strip_tags(the_excerpt()); ?>
Run Code Online (Sandbox Code Playgroud)
与我打算删除所有ellipses
,<p>
标签和其他shortcodes
和links
,但是,这并不在所有的工作.
如果我将鼠标悬停在锚点上,我仍然可以看到<p>
摘录中包含的内容,以及其他标签和网址链接.我做错了什么,我需要做些什么才能让它发挥作用?
Joh*_*han 14
你需要的是什么 get_the_excerpt():
<a href='<?php the_permalink() ?>' title='<?php echo strip_tags( get_the_excerpt() ); ?>'>
Run Code Online (Sandbox Code Playgroud)
但是,它可能不会删除省略号(...),因为它们是HTML实体,而不是标签.
小智 5
这是因为 the_excerpt() 立即输出摘录。您需要 get_the_excerpt() 它将其作为字符串返回,您可以手动输入(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());
Run Code Online (Sandbox Code Playgroud)