neufuture
Member
Posted 2 years ago #
It is annoying that the_excerpt() adds a <p> tag surrounding text or html, so I made a quick hack to remove them.:
<?php
$myExcerpt = get_the_excerpt();
$tags = array("<p>", "</p>");
$myExcerpt = str_replace($tags, "", $myExcerpt);
echo $myExcerpt;
?>
monkeychubs
Member
Posted 2 years ago #
That's brilliant - thank you very much!
Does seem a bit odd that it comes with <p> tags by default, it's much more use without them and so easy to add if required.
Thanks for the hack. I also suggest that the_excerpt should come without <p> and it cud be added if reqd by developers in the theme.
xiatica
Member
Posted 2 years ago #
Nice one, thanks.
I agree, p should be removed from the excerpt in general.
rperezmicheli
Member
Posted 2 years ago #
Nice. Just what I was looking for. Remember to tell folks to replace the excerpt call in index.php with this code. I commented out the old code and made a comment noting this new code and what it does. Thanks!
richard.calahan
Member
Posted 2 years ago #
You can technically just call
<?php echo get_the_excerpt(); ?>
instead of
<?php the_excerpt(); ?>
the first bit of code will not include paragraph tags. The function is looking for <p> tags that aren't there.
jezThomp
Member
Posted 2 years ago #
Thanks Richard, thats awesome.
Where do i put this code to remove those annoying p tags???
richard.calahan
Member
Posted 1 year ago #
You simply call <?php echo get_the_excerpt(); ?> instead of <?php the_excerpt(); ?>
The first tag is designed to retrieve the excerpt in plain text for manipulation in php functions, so if all you want to do is get rid of html tags, thats your answer. Just make sure you 'echo' or 'print' it, since by default it won't render a display in your browser.