Additions to the Plugin
-
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/
- The topic ‘Additions to the Plugin’ is closed to new replies.