• Resolved godthor

    (@godthor)


    The plugin is great but I added a few features to it that I thought I would pass along to see if you wanted to include in the plugin.

    I wanted to create an image element as well as the media:thumbnail so I added the following code to the plugin.

    function add_image_nodes() {
    	global $post;
    	if(has_post_thumbnail($post->ID)):
    		$featured_images_in_rss_size = get_option('featured_images_in_rss_size');
    		$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $featured_images_in_rss_size);
    
    		if(!$thumbnail[1] && !$thumbnail[2]) {
    			// See if it's Photon
    			$url = parse_url($thumbnail[0]);
    
    			if($url) {
    				$sizes = explode('%2C', $url['query']);
    				$thumbnail[1] = str_replace('resize=','', $sizes[0]);
    				$thumbnail[2] = $sizes[1];
    			}
    		}
    
    		echo "\t<image>
    		    <url>" . $thumbnail[0] . "</url>
    		    <title>" . get_the_title($post->ID) . "</title>
    		    <link>" . get_permalink($post->ID) . "</link>
    		  </image>\n";
    		echo("\t\t<media:thumbnail xmlns:media=\"https://search.yahoo.com/mrss/\" url=\"" . $thumbnail[0] . "\" height=\"" . $thumbnail[2] . "\" width=\"" . $thumbnail[1] . "\" />\n");
    	endif;
    }
    
    add_action('rss2_item', 'add_image_nodes');

    It uses your code to check the size being used and then uses that in the two new nodes. It also has a check to see if Jetpack’s Photon is being used since the image width and height are not returned by the wp_get_attachment_image_src() function if it is. If Photon is being used it then parses out the size attributes to set them appropriately.

    You would probably want to break this out to separate the image element and media:thumbnail so they are options to the user, whether to use either.

    https://www.ads-software.com/plugins/featured-images-for-rss-feeds/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Very nice, explain what the media:thumbnail is different from the image element? It adds that specific XML tag to the output as well? I’ve heard of it but not clear on what it’s used for or by which sites, etc…

    Thread Starter godthor

    (@godthor)

    I honestly threw the image element in there as a test so see if a particular RSS aggregator used it, which it didn’t. Some readers will use the image element but from my testing I have not found one that does so you could safely dump that.

    Ah thanks, I’ll look into updating the plugin to support the media:thumbnail and the Photon sizing, much appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Additions to the Plugin’ is closed to new replies.