In a post I have some text and some media attachments and when I use the_excerpt(), it strips all the anchor tags from the attachments and shows just their file names and its causing me problems as some of the filenames are really long. Is there a way of excluding media attachment content from the_excerpt()?

If not, is there a way to show the anchor tags when using the_excerpt() that wont leave unclosed tags and what not?

2 Answers 2


If you manually provide an excerpt for the post WordPress will use the one you provided instead of automatically generating one. Any HTML links you include in your manual excerpt will still be displayed correctly. Or you can leave the links out and just include the text you want.

To preserve HTML links in the automatically generated excerpt you could try this tutorial: How To preserve HTML Tags in WordPress Excerpt Without a Plugin

  • Im using the_excerpt in my search template, so i would have to manually enter one for each post (theres around 500+), so I cant do that. I tried that function (as well as every other I could find on the net) but if the last word shown is a word before a link, it causes unclosed html elements :(
    – RoseCoder
    Aug 19, 2013 at 16:51
  • That is the difficulty with filtering the content. It's far easier to remove all the HTML then to look for unclosed HTML elements and close them. Sorry I can't help more.
    – epilektric
    Aug 20, 2013 at 0:12
  • Yeah, i see what you mean! I'll go a css route and work with the text overflow instead. Thanks for your help!
    – RoseCoder
    Aug 20, 2013 at 8:50

Is there a way of excluding media attachment content from the_excerpt()?

Yes. There are many ways. Here are a few:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.