I think I might have worked around my RSS feed compatibility issues for title-less posts (seeing as how many feed readers don't handle them elegantly.)

The RSS 2.0 spec states:

"An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed; see examples), and the link and title may be omitted."

But, as we already know, it the item title is empty or not present, many readers will use the description as a fallback which can cause the problem of HTML tags appearing in the text used for the title.

To get round this I have now set up a custom template and trimmed the description to just the first 10 words of the post content with the code below:

<?php $content = get_the_content_feed('rss2'); ?>
<description><?php echo htmlentities(wp_trim_words($content, 10)); ?></description>

This gets the first 10 actual words, excluding tags, and adds an ellipsis.

When a title exists feed readers should use the <content:encoded> element which contains the full, entity-encoded text.

Hopefully, this will make things look just a little better in all cases until more readers adequately support title-less posts.

Updated to include htmlentities()

Leave a Reply

Your email address will not be published.