One attention-grabbing factor about WordPress is that the featured picture has by no means been included into the RSS feed. This can be a bit unlucky, as choosing or designing the featured picture can draw a lot consideration to an article.
Prepend Content material To The Posts In Your RSS Feed
To prepend the featured picture to your content material isn’t too tough. Right here’s the code that I added to my WordPress features.php
in my Little one Theme file:
operate prerssfeedcontent($content material) {
world $publish;
$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 picture
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 material = $precontent . $content material;
return $content material;
}
add_filter('the_excerpt_rss', 'prerssfeedcontent');
add_filter('the_content_feed', 'prerssfeedcontent');
Moreover, I additionally wish to add content material on the finish of my feed posts.
Append Content material To The Posts In Your RSS Feed
As I’m reviewing backlinks to Martech Zone, I usually discover that there are websites which are stealing my content material and publishing it as their very own on their web site. It’s an infinite chase and aggravating. There are many instances that I can monitor them down; different instances, I can report them to their advert networks and internet hosting suppliers. However usually, they’re largely nameless and arduous to trace down… if in any respect.
Because of this, my solely selection is to customise my feed and embrace a copyright assertion so unauthorized web site guests can see the supply. To do that, I up to date the above operate to prepend and append the data I needed.
operate prepostrssfeedcontent($content material) {
world $publish;
$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://dknewmedia.com";
// Add the featured picture
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>Initially Printed on Martech Zone: <a href="'.$post_link.'">'.$post_title.'</a></p>';
$content material = $precontent . $content material . $postcontent;
return $content material;
}
add_filter('the_excerpt_rss', 'prepostrssfeedcontent');
add_filter('the_content_feed', 'prepostrssfeedcontent');
You possibly can view the end result on my feed… the featured picture is displayed in addition to the copyright and unique supply hyperlinks on the finish of every publish.