Created
February 8, 2018 21:28
-
-
Save alexminza/97c4e71061bf2be4fca63918d9d3d8ad to your computer and use it in GitHub Desktop.
WooCommerce rss2_item action - add blog posts featured images to RSS feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//https://codex.wordpress.org/Plugin_API/Action_Reference/rss2_item | |
//https://validator.w3.org/feed/ | |
function add_rss_featured_image() { | |
global $post; | |
if(has_post_thumbnail($post->ID)) { | |
$thumbnail_id = get_post_thumbnail_id($post->ID); | |
$thumbnail = wp_get_attachment_image_src($thumbnail_id, 'large'); | |
$output = sprintf('<media:content xmlns:media="http://search.yahoo.com/mrss/" medium="image" type="%1$s" url="%2$s" width="%3$s" height="%4$s" />', | |
get_post_mime_type($thumbnail_id), | |
esc_url($thumbnail[0]), | |
$thumbnail[1], | |
$thumbnail[2]); | |
echo $output; | |
} | |
} | |
add_action('rss2_item', 'add_rss_featured_image'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment