Wednesday, January 29, 2020

Add Logo or Image to WordPress RSS Feed – WordPress hacks

wp-rssWordPress is undoubtedly one of the best and popular CMS/blogging platform available, clearly evident by its developer ecosystem. One of the most common issues faced by webmasters using wordpress is to customize the theme, for a variety of reasons. Of many such customizations, the RSS feed back is one of the lesser known wordpress hacks. A question that might come to mind is, why customize the wordpress rss page.

Well for starters, adding a logo or an image to the RSS page gives it a better aesthetic appeal and also makes your site look more professional. There are many plugins out there that can do this job. However the issue with WordPress being that the more plugins you use, the more resource heavy your website becomes, thus eventually slowing down your site speed. In this wordpress hack, we show you how to add a logo or image to your wordpress rss feed.

Note: Before making any changes ALWAYS take a backup of your MySQL database as well as your wordpress posts and the theme files as well. In fact a good practice is to take monthly backups of your theme files and weekly backups of your SQL DB.

Adding Logo to WordPress RSS Feed

Open your theme’s functions.php file. Most wordpress themes today come with more than one functions file, so its easy to get confused. By default there is only one file functions.php that executes all the functions you declare.

Copy the code below and append/paste it into your functions.php file


/* Add RSS Logo */
function addRssImage() {
  echo "<image>
    <url>" . get_bloginfo('template_directory') . "PATH-TO-YOUR-LOGO.png</url>
    <link>" . get_bloginfo('url') ."</link>
add_action('rss2_head', 'addRssImage');
/* End RSS Logo */

Explanation of the code

The above piece of code simply adds additional field called ‘Image’ to your RSS/XML files. Therefore in order for this to work, simply make a note of the folder where your logo or image resides and replace “PATH-TO-YOUR-LOGO.png” with the path. Note that the get_bloginfo(‘template_directory’) automatically calls the folder where your template resides, which in most cases is wp-content/themes/

Adjust the width and the height parameters and replace the Title and the description elements with the appropriate information.

The Output

Add image to rss feed in WordPressNOTE: Always back up your files before making any changes to your wordpress files.

Leave a Reply

Your email address will not be published. Required fields are marked *