Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Richard Walton10,861 Points
Why is PHP adding the <p> tag?
so we are showed how to fix it, but why did PHP add those tags causing the problem in the first place? Is there a way to set the page up so that it doesn't do it in the first place?
Hi Richard, the fact that parapgrahs are added with the the_excerpt wordpress function is due to the way this function is coded inside wordpress with PHP, I don't know why they chose to build this function this way as It's easy to add paragraph tags.
However, I "investigated" a little bit and I found that while the the_excerpt function automatically adds paragraph tags, It's not the case with the get_the_excerpt function. So there is no need to strip tags as Zac showed in the video.
Once again I don't know why they chose to include them with one of the two function and not the other.
Moreover, It's not that much an issue if you use the strip_tags() function even if there are no tags to strip.
In conclusion just use:
<h2><?php echo get_the_excerpt(); ?></h2>
FInally if you want a hack to delete the paragraph tags with the the_excerpt function, here is a topic.