Last active
August 16, 2023 14:02
-
-
Save wpscholar/0ddf40fa3a72456e718f84e50ef90677 to your computer and use it in GitHub Desktop.
Add the featured image to RSS feed(s)
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 | |
/** | |
* Add Featured Image to RSS Feed | |
* | |
* @package AddFeaturedImageToRssFeed | |
* @author Micah Wood | |
* @copyright Copyright 2023 by Micah Wood - All rights reserved. | |
* @license GPL2.0-or-later | |
* | |
* @wordpress-plugin | |
* Plugin Name: Add Featured Image to RSS Feed | |
* Plugin URI: https://gist.github.com/wpscholar/0ddf40fa3a72456e718f84e50ef90677 | |
* Description: Adds featured images to all RSS feeds, if set. | |
* Version: 1.0 | |
* Requires PHP: 7.4 | |
* Requires at least: 6.0 | |
* Author: Micah Wood | |
* Author URI: https://wpscholar.com | |
* Text Domain: add-featured-image-to-rss-feed | |
* Domain Path: /languages | |
* License: GPL V2 or later | |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
function addFeaturedImageToFeed( $content ) { | |
if ( has_post_thumbnail( get_the_ID() ) ) { | |
$content = '<div>' . get_the_post_thumbnail( get_the_ID(), 'large', [ 'style' => 'margin-bottom: 15px;' ] ) . '</div>' . $content; | |
} | |
return $content; | |
} | |
add_filter( 'the_excerpt_rss', 'addFeaturedImageToFeed' ); | |
add_filter( 'the_content_feed', 'addFeaturedImageToFeed' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment