admin管理员组文章数量:1134232
In the code snippet below, I trying to get the_excerpt to be written out without tags. However, the source formatting shows that the_excerpt is always wrapped in P tags. How can I pull the excerpt without tags?
foreach($myrecentposts as $idxrecent=>$post)
{ ?>
<li class="page_item">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php echo strip_tags(substr( the_excerpt(), 0, 75 ))."..." ?>
</li><?php }
echo "</ul>
</div>";}
In the code snippet below, I trying to get the_excerpt to be written out without tags. However, the source formatting shows that the_excerpt is always wrapped in P tags. How can I pull the excerpt without tags?
foreach($myrecentposts as $idxrecent=>$post)
{ ?>
<li class="page_item">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php echo strip_tags(substr( the_excerpt(), 0, 75 ))."..." ?>
</li><?php }
echo "</ul>
</div>";}
Share
Improve this question
asked Jan 13, 2011 at 20:59
Scott BScott B
5,69614 gold badges94 silver badges148 bronze badges
6 Answers
Reset to default 19in your code above use get_the_excerpt()
instead of the_excerpt()
, because the last one will output the excerpt to the screen, and not pass it to your other functions...
What about removing the wpautop
filter before your list?
remove_filter( 'the_excerpt', 'wpautop' );
(Make sure to add it back afterwards, so as not to mess up other formatting...)
I tried the above answers but didn't work for me.
I tried using the_excerpt but wasn't displaying any content so I used the below and it worked perfectly
// $search_text = the_excerpt();
$search_text = get_the_excerpt();
// Strip the <p> tag by replacing it empty string
$tags = array("<p>", "</p>");
$search_content = str_replace($tags, "", $search_text);
// Echo the content
echo $search_content;
I hope this throws more light for someone else too.
Cheers
<?php echo strip_tags(get_the_excerpt()); ?>
this worked for me
sorry for this => Body must be at least 30 characters; you entered 18.
If you dont want <p>
tags when using the_excerpt()
, you can use echo get_the_excerpt()
instead, which strip <p>
tags.
If you also want to make sure that you remove linebreaks and whitespace you can use echo wp_strip_all_tags( get_the_excerpt(), true );
.
Using get_the_excerpt
, might cause an undefined offset -1, then you need to check first with has_excerpt()
.
Below did the trick using ACF plugin:
<p>
<?php
$summary = get_field('introductory_text');
echo strip_tags(substr($summary, 0, 520));
?>
<a href="<?php the_permalink(); ?>"> ...read more</a>
</p>
本文标签: plugin developmentHow to echo theexcerpt without the P tag wrapper
版权声明:本文标题:plugin development - How to echo the_excerpt without the P tag wrapper? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736769827a1952021.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论