Last Updated: March 20, 2018
·
663
· kosal

Add Custom XML Tags into Wordpress Feed

Custom RSS Feed

Here's a simple, quick solution to adding your own custom tags into the XML document of the Wordpress RSS feed.

Usage

This code must reside in your function.php file.

/**
 *  Add custom XML tag to the RSS feed
 */
function custom_xml_tags($query) {
    echo '<gravatar>https://www.gravatar.com/avatar/' . md5(get_the_author_meta('user_email')) . '?s=100&d=mm</gravatar>';
}
function add_custom_to_feed($query) {
    if ($query->is_feed) {
        add_filter('rss2_item', 'custom_xml_tags');
        add_filter('rss_item', 'custom_xml_tags');
    }
    return $query;
}
add_filter('pre_get_posts','add_custom_to_feed');

Getting the author's Gravatar image

I'm using the get_the_author_meta() function to grab the author's email address and md5() hash it to retrieve the image.