WordPress Posts Without Titles in RSS feeds
Some RSS readers and aggregators will display things like “no title” or “untitled” for posts without a title in WordPress, which looks pretty awful. I’ve been playing around with post formats lately and things like links, quotes and images are fine without titles sometimes, but at other times they do require a title, so we can’t just “disable/hide” for all.
So I browsed around to see how others are doing it and of course looked at how Tumblr does it. When writing anything in Tumblr, it clearly tells you that the title is optional and most Tumblr themes are okay with that. I looked at how RSS feed entries without titles look and guess what! They’re displaying an excerpt. Not a 55 word excerpt but a shorter one.
So here’s a snippet for your functions.php file that wouldn’t let feed entries go without titles. It will look for an empty title and replace with a 15 word excerpt.
add_filter( 'the_title_rss', 'my_feed_title' );
public function my_feed_title( $title ) {
if ( strlen( trim( $title ) ) < 1 ) {
$words = preg_split( "/[nrt ]+/", get_the_excerpt(), 15, PREG_SPLIT_NO_EMPTY );
array_pop( $words );
$title = implode( ' ', $words ) . ' ...';
}
return $title;
}
Hopefully a similar technique can be implemented for titles in the theme head section (or for SEO plugins that rewrite them), post titles in the commenting section, in popular posts lists and so on.
I do believe that titles are essential when it comes to articles, essays, tutorials and so on. But I also believe that things like asides, a link, a photo of your dog or a quote by Steve Jobs can look quite dirty (design-wise) with huge titles attached to them.
So who’s to blame? RSS aggregators for not being able to generate a title on their own? Or WordPress for not being able to provide one when absent? The RSS 2 specification says that all the elements in an item are optional, however “at least one of title or description must be present.”
I didn’t mind until I received a few comments from my friends and followers saying my RSS feed is broken. Also, things like Twitterfeed, Feedburner Socialize and so on stop working if they’re sharing titles and links only, so you get a lonely link in Twitter, doh!
