Improving WordPress Part 2 – Better Auto Excerpts and Feeds

ADVERTISEMENT:

WordPress allows most HTML in the post_content field, allowing a fair amount of flexibility for formatting post content for browsers. However, when that content needs to be presented in feeds or excerpts, it is run through a set of sanitizing filters that strips this HTML, leaving bare text.

For the most part this works ok, but when WordPress strips block level tags like <div>, <blockquote>, or even <br>, the remaining text can be jammed together, causing words to run together.

It would normally be a fairly simple task to add a regular expression which would add whitespace around such tags, before stripping them. However, WordPress considers the functions in question so integral to the core functionality, that they do not include any filters to hook to at all.

To address this shortcoming, I needed to step back a few levels, and rewrite several WordPress core functions from the last place there is a usable hook. To save you all the trouble i went through, here is a single-file plugin that will insert the relevant missing formatting:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>