Created
September 12, 2017 10:00
-
-
Save danielck/05794333ce8cfeea2517d7d3a2fd8a4b to your computer and use it in GitHub Desktop.
WordPress add featured image to RSS
This file contains hidden or 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 | |
/** | |
* Plugin Name: ZF Featured Image in RSS | |
* Description: Adds the featured image URL (large) to its own RSS field for easy parsing with e.g. Feed Pull. | |
* Author: Zeeland Family | |
* Version: 1.0.0 | |
* Licence: GPLv3 | |
*/ | |
add_action( 'rss2_item', 'featured_image_field_in_rss' ); | |
/** | |
* Adds the featured image URL (large) to its own RSS field for easy parsing with e.g. Feed Pull. | |
*/ | |
function zf_featured_image_field_in_rss() { | |
global $post; | |
if ( has_post_thumbnail( $post->ID ) ) { | |
$thumbnail = wp_get_attachment_image_url( get_post_thumbnail_id( $post->ID ), 'large' ); | |
echo( '<image>' . esc_url( $thumbnail ) . '</image>' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment