Created
June 16, 2016 14:41
-
-
Save bmodena/be55fae5ac02ad093454c0080a5e5307 to your computer and use it in GitHub Desktop.
Wordpress Featured Image in 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
/* | |
* @param - DEFAULTIMG - declared as global constant | |
* define("DEFAULTIMG", "/wp-content/themes/[theme-name]/public/images/[path-to-img.jpg]"); | |
* | |
*/ | |
// Add Featured image item to rss feed | |
function featuredtoRSS() { | |
global $post; | |
if ( has_post_thumbnail( $post->ID ) ){ | |
$thumb_id = get_post_thumbnail_id(); | |
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'large', true); | |
$image = $thumb_url_array[0]; | |
} else { | |
$image = '/wp-content/themes/angelfiremega/public/images/af-logo.jpg' ; | |
} ?> | |
<featuredimage><?php echo( $image ); ?></featuredimage> | |
<?php } | |
// Add featured image to feeds | |
add_action('rss_item','featuredtoRSS'); | |
add_action('rss2_item','featuredtoRSS'); | |
add_action('commentsrss2_item','featuredtoRSS'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment