How to Get WordPress Featured Images to Show in a Blogger (Blogspot) Blogroll

A huge frustration of mine for years was getting Blogger sites to pull my site’s featured image in its blogroll. I have a wargaming site called Creative Twilight, and one of the things many of us wargamers do is the old school blogroll exchange. I know it has little value for SEO, but it’s about building a community, not pushing backlinks.

Anyway, I could never get a Blogger site to pull my WordPress featured image from my RSS feed to show. Until one day I finally figured it out!

Now, the other thing the code below does is truncates the post at 100 words (creating an excerpt), and it adds a link in your RSS feed for continue reading. These can be adjusted as noted below.

RSS Feed Code

This code will go into your theme’s functions.php file. As always, I’d recommend using a child theme.

add_action('rss2_item', array($this,'rss_add_media_thumbnail'));
add_filter('the_excerpt_rss', array($this,'rss_add_image'));

function rss_add_image($content) {
	global $post;

	$num_words = 100;
	$new_content = strip_shortcodes(wp_strip_all_tags($post->post_content));
	$new_content = wp_trim_words($new_content, $num_words,'...<a href="' . get_permalink($post->ID) . '">continue reading</a>');

	if(has_post_thumbnail($post->ID)) {
		$fimage = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'medium');
		list($width, $height, $type, $attr) = getimagesize($fimage[0]);
		$image = $fimage[0];

		$new_content = '<img src="' . $image . '" width="' . $width . '" height="' . $height . '" style="float: left; margin: 0 10px 10px 0;">' . $new_content;
	}

	return $new_content;
}
function rss_add_media_thumbnail() {
	global $post;

	if(has_post_thumbnail($post->ID)) {
		$thumb_ID = get_post_thumbnail_id( $post->ID );
		$details = wp_get_attachment_image_src($thumb_ID, 'thumbnail');

		if(is_array($details)) {
			echo '<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="' . $details[0]
			. '" width="' . $details[1] 
			. '" height="' . $details[2] . '" />';
		}
	}
}

Now, if you want to change the 100 words in the excerpt then just adjust the line: $num_words = 100; and change the 100 to however many words you’d prefer.

If you do not want to create an excerpt then simply remove the line below. That will also remove the continue reading link.

$new_content = wp_trim_words($new_content, $num_words,'...<a href="' . get_permalink($post->ID) . '">continue reading</a>');

Lastly, if you’d like to change the image size that’s used (medium in my code), then look for this line:

$fimage = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'medium');

and you can change medium as needed. See this page for more information.

As a Plugin

You can easily turn this into a plugin as well. That way you can move it site to site easily, and not have to worry about adding it to every theme’s functions.php file.

To make this a plugin you really only need to add a few more details.

<?php

/*
	Plugin Name: Featured Image in RSS
	Plugin URI: http://blogplayground.com/
	Description: Add your featured image to your RSS, as well as a continue reading link.
	Author: Thor
	Version: 1.0.0
	Author URI: http://blogplayground.com/
*/

add_action('rss2_item', array($this,'rss_add_media_thumbnail'));
add_filter('the_excerpt_rss', array($this,'rss_add_image'));

function rss_add_image($content) {
	global $post;

	$num_words = 100;
	$new_content = strip_shortcodes(wp_strip_all_tags($post->post_content));
	$new_content = wp_trim_words($new_content, $num_words,'...<a href="' . get_permalink($post->ID) . '">continue reading</a>');

	if(has_post_thumbnail($post->ID)) {
		$fimage = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'medium');
		list($width, $height, $type, $attr) = getimagesize($fimage[0]);
		$image = $fimage[0];

		$new_content = '<img src="' . $image . '" width="' . $width . '" height="' . $height . '" style="float: left; margin: 0 10px 10px 0;">' . $new_content;
	}

	return $new_content;
}
function rss_add_media_thumbnail() {
	global $post;

	if(has_post_thumbnail($post->ID)) {
		$thumb_ID = get_post_thumbnail_id( $post->ID );
		$details = wp_get_attachment_image_src($thumb_ID, 'thumbnail');

		if(is_array($details)) {
			echo '<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="' . $details[0]
			. '" width="' . $details[1] 
			. '" height="' . $details[2] . '" />';
		}
	}
}

?>

Conclusion

And there you have it!

The magic that gets Blogger to actually see the featured image is in creating the media element in the rss_add_media_thumbnail() function. If you wanted, you could strip it all down to that if it’s all you’re after; while of course leaving the action to trigger it.

Please Rate this Article

Please take a second to rate this. It helps us deliver to you the stuff you enjoy.

How to Get WordPress Featured Images to Show in a Blogger (Blogspot) Blogroll
5 (100%) 1 vote

Author: Thor

I started blogging in 2009 for my wargaming blog. I've been blogging ever since. I even created a niche site about miniature storage of all things.

I have created a free 40K roster builder. I've also set up, maintain, and run my wife's site where she sells the Makeup Eraser.

I'm also a PHP programmer for a local web hosting company where I develop WordPress plugins.

Leave a Reply!

Note: You can comment as a guest by clicking the field indicated Name and checking off “