I have done an excessive amount of googling and haven't found exactly what I need yet.

The client uses the editor (WYSIWYG) to create posts. She adds photos, links to external photos, videos, embeds external videos, and all other formatting. But she does not use the tag nor the excerpt field.

When I use wp_trim_words() I get mixed results.

  • Posts with local videos leak markup onto the page
  • A couple posts are only images so there isn't any content at all
  • Posts with a lot of formatting look really wonky

Anyone have any other ideas on how to trim content or better ways to use wp_trim_words() ?

EDIT: To make myself clear basically what I want is a trimmed version of the full post that still contains all the formatting, images, videos, links, embeds, whatever else she throws into the editor. I do not want markup leaking through, obviously.

1 Answer 1


wp_strip_all_tags() will strip out all the tags.

However with posts which just have images and no content. There is no solution to that, the excerpt or wherever you are trying to use it will show blank since it cannot "magically" create content for the post when there is no content at all.

For more info > https://codex.wordpress.org/Function_Reference/wp_strip_all_tags


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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