Customize Your WordPress Feed With A Featured Image and Copyright Statement (Pre and Post Content)
One interesting thing about WordPress is that the featured image has never been incorporated into the RSS feed. This is a bit unfortunate, as selecting or designing the featured image can draw much attention to an article.
Prepend Content To The Posts In Your RSS Feed
To prepend the featured image to your content isn’t too difficult. Here’s the code that I added to my WordPress functions.php
in my Child Theme file:
function prerssfeedcontent($content) {
global $post;
$current_year = date('Y');
$post_title = get_the_title( $post->ID );
$post_link = get_permalink( $post->ID );
$post_image = get_the_post_thumbnail( $post->ID, 'medium' );
// Add the featured image
if ( has_post_thumbnail( $post->ID ) ) {
$precontent = '<p class="thumb">';
$precontent .= '<a href="' .$post_link. '" title="' .$post_title. '">';
$precontent .= $post_image;
$precontent .= '</a></p>';
}
$content = $precontent . $content;
return $content;
}
add_filter('the_excerpt_rss', 'prerssfeedcontent');
add_filter('the_content_feed', 'prerssfeedcontent');
Additionally, I also want to add content at the end of my feed posts.
Append Content To The Posts In Your RSS Feed
As I’m reviewing backlinks to Martech Zone, I often find that there are sites that are stealing my content and publishing it as their own on their site. It’s an endless chase and aggravating. There are plenty of times that I can track them down; other times, I can report them to their ad networks and hosting providers. But often, they’re largely anonymous and hard to track down… if at all.
As a result, my only choice is to customize my feed and include a copyright statement so unauthorized site visitors can see the source. To do this, I updated the above function to prepend and append the information I wanted.
function prepostrssfeedcontent($content) {
global $post;
$current_year = date('Y');
$post_title = get_the_title( $post->ID );
$post_link = get_permalink( $post->ID );
$post_image = get_the_post_thumbnail( $post->ID, 'medium' );
$company_title = "DK New Media, LLC";
$company_link = "https://martech.zone/partner/dknewmedia/";
// Add the featured image
if ( has_post_thumbnail( $post->ID ) ) {
$precontent = '<p class="thumb">';
$precontent .= '<a href="' .$post_link. '" title="' .$post_title. '">';
$precontent .= $post_image;
$precontent .= '</a></p>';
}
// Add the copyright
$postcontent = '<p>©';
$postcontent .= $current_year;
$postcontent .= ' <a href="'.$company_link.'">'.$company_title.'</a>, All rights reserved.</p>';
$postcontent .= '<p>Originally Published on Martech Zone: <a href="'.$post_link.'">'.$post_title.'</a></p>';
$content = $precontent . $content . $postcontent;
return $content;
}
add_filter('the_excerpt_rss', 'prepostrssfeedcontent');
add_filter('the_content_feed', 'prepostrssfeedcontent');
You can view the result on my feed… the featured image is displayed as well as the copyright and original source links at the end of each post.