Skip to content

Instantly share code, notes, and snippets.

@mattpramschufer
Created January 11, 2017 14:04
Show Gist options
  • Save mattpramschufer/3d11123879fe2e962ed805c140d6b01e to your computer and use it in GitHub Desktop.
Save mattpramschufer/3d11123879fe2e962ed805c140d6b01e to your computer and use it in GitHub Desktop.
Add Featured Image to RSS Feed Description and Create separate image Node in Wordpress,
<?php
// Add the image and thumbnail node to RSS feed
function add_rss_node_image_thumbnail() {
global $post;
if (has_post_thumbnail($post->ID)):
echo "<image>" . get_the_post_thumbnail_url($post->ID, 'medium') . "</image>\n";
endif;
}
add_action('rss2_item', 'add_rss_node_image_thumbnail');
function add_rss_image_thumbnail($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '<div>' . get_the_post_thumbnail( $post->ID, 'large' ) . '</div>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'add_rss_image_thumbnail');
add_filter('the_content_feed', 'add_rss_image_thumbnail');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment