How to echo the_excerpt without the P tag wrapper?

Question

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 progress 0
Scott B 11 years 2011-01-13T14:59:00-05:00 0 Answers 75 views 0

Answers ( 2 )

    0
    2021-08-01T10:20:01-05:00

    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…)

    0
    2021-08-01T10:20:19-05:00

    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…)

Leave an answer

Browse
Browse