• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Programming / WordPress Add Content to RSS Feed

WordPress Add Content to RSS Feed

Last updated on May 12, 2016 by Sal Ferrarello

Recently, I wanted to add content to each item in the RSS feed on a WordPress site. This could be something like:

Hire Sal

If you enjoyed this article, have you considered hiring Sal to help with your project?

To add this, we can leverage the WordPress filter the_content_feed. The code would look something like

add_filter( 'the_content_feed', 'fe_the_content_feed_add_hire_sal_blurb' );

function fe_the_content_feed_add_hire_sal_blurb( $content ) {

    $hire_sal_blurb = "\n<h3>Hire Sal</h3>\n" 
        . '<p>If you enjoyed this article, have you considered '
        . '<a href="https://ironcodestudio.com/contact-us/">hiring Sal</a> '
        . "to help with your project?</p>\n";

    return $content . $hire_sal_blurb;
}

Testing

There are a couple of challenges with testing RSS feeds.

Caching

Web browsers cache RSS feeds aggressively, so if you’re looking at the feed in the browser (e.g. https://salferrarello.com/feed/) your updates won’t show up in a timely manner.

If you’re familiar with Chrome developer tools, you can use it to Disable cache (while DevTools is open) to insure you are loading the most recent version. Alternatively, you can use the command line tool curl to view the feed without caching.

curl https://salferrarello.com/feed/

Local Development

For developing locally and previewing the rendered RSS feed, I find Vienna RSS Reader to be a good tool. Generally I read RSS feeds with an online RSS Reader (Feedbin) but an online RSS Reader doesn’t work for a local feed.

Note: When using Vienna, you will have to delete the feed and re-add it to clear the cache for a feed.

Image Credits:

RSS Icon and Post It

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Programming Tagged With: WordPress, WordPress Filter

Reader Interactions

Comments

  1. Bryan George says

    May 12, 2016 at 7:44 pm

    Sal nice classed tonite at Lehigh Valley WordPress Meetup

    Reply
    • Sal Ferrarello says

      May 13, 2016 at 9:16 am

      Thanks Bryan. I had a lot of fun at the Lehigh Valley WordPress Meetup.

      For anyone else interested, here is the link for my slides on WordPress filters.

      Reply

Leave a Reply Cancel reply

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

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in