Family Encyclopedia >> Electronics

Expert Guide: Fully Customize WordPress RSS Feeds with PHP Functions

At WPBeginner, we've long helped site owners optimize their WordPress RSS feeds. Previously, we recommended the RSS Footer plugin by Joost de Valk for simple footer additions. While reliable, it's limited to static text across all posts. Need dynamic content per post, custom RSS titles, or specific custom fields? This advanced tutorial, drawn from years of hands-on WordPress development, gives you complete control over your RSS feeds using targeted PHP functions in functions.php.

Important: This is for experienced users comfortable editing theme functions.php and basic PHP. Beginners should stick with plugins or hire experts like our team.

1. Add Custom Fields to RSS Post Content

Use custom fields to inject unique text, ads, images, or HTML per post in your RSS feeds—ideal for FTC compliance on varied content types.

Add this to your theme's functions.php:

function wpbeginner_postrss($content) {
    global $wp_query;
    $postid = $wp_query->post->ID;
    $coolcustom = get_post_meta($postid, 'coolcustom', true);
    if (is_feed()) {
        if ($coolcustom != '') {
            $content .= '<br /><br />' . $coolcustom . '<br />';
        }
    }
    return $content;
}
add_filter('the_excerpt_rss', 'wpbeginner_postrss');
add_filter('the_content_rss', 'wpbeginner_postrss');

How it works: The function checks each post for a 'coolcustom' meta field via global query. If present and in a feed, it appends the value post-content without affecting site display, ensuring compatibility. Unlike plugins, this varies per post.

2. Customize RSS Post Titles

Label guest posts, sponsored content, or reviews directly in RSS readers—preserving context stripped by feeds.

Example: Turn "Commercial WordPress Theme - StudioPress" into "Sponsored Post: Commercial WordPress Theme - StudioPress".

Add this code:

function wpbeginner_titlerss($title) {
    global $wp_query;
    $postid = $wp_query->post->ID;
    $gpost = get_post_meta($postid, 'guest_post', true);
    $spost = get_post_meta($postid, 'sponsor_post', true);
    if ($gpost != '') {
        $title = 'Guest Post: ' . $title;
    } elseif ($spost != '') {
        $title = 'Sponsored Post: ' . $title;
    }
    return $title;
}
add_filter('the_title_rss', 'wpbeginner_titlerss');

Explanation: Checks 'guest_post' or 'sponsor_post' meta (any non-empty value). Prioritizes guest, then sponsor; defaults to original title. RSS-only via the_title_rss filter.

To append categories (e.g., "Get Contact Form 7 (Plugins)"):

function wpbeginner_cattitlerss($title) {
    $postcat = '';
    foreach (get_the_category() as $cat) {
        $postcat .= '(' . $cat->cat_name . ')';
    }
    $title .= $postcat;
    return $title;
}
add_filter('the_title_rss', 'wpbeginner_cattitlerss');

3. Add Static Text to All RSS Posts

For uniform additions like bylines or links, skip plugins—use this lightweight approach:

function wpbeginner_postrss_static($content) {
    if (is_feed()) {
        $content = 'This post was written by Syed Balkhi. ' . $content . ' Check out WPBeginner';
    }
    return $content;
}
add_filter('the_excerpt_rss', 'wpbeginner_postrss_static');
add_filter('the_content_rss', 'wpbeginner_postrss_static');

Explanation: Prepends/append byline RSS-only. Perfect for ads, disclosures, or branding.

Inspired by Joost de Valk's RSS Footer plugin and adapted from advanced tutorials, with custom enhancements for per-post flexibility. Tested across major WordPress versions.