Adding Post Feeds to the wordpress Header
October 29, 2008 · Print This Article
WordPress generates a unique RSS feed for each post on your blog, which can by default be accessed in the post metadata section below the post itself.
However, in order to make the most of your feed you need a link element pointing to it, telling browsers, bots, and whatever and whoever else might be accessing your page that this is a feed, not just any old XML file.
Unfortunately WordPress doesn’t provide a dedicated option for doing this yet, so we’re going to have to make one ourselves.
<?php if (is_single()) { ?>
<?php while (have_posts()) : the_post(); ?>
<link rel="alternate" type="application/rss+xml" title="<?php the_title(); ?> Comments" href="<?php bloginfo('url'); ?>/?feed=rss2&p=<?php the_ID(); ?>" />
<?php endwhile; ?>
<?php rewind_posts(); ?>
<?php } ?>
Paste this code into header.php (preferably next to the existing site feed, for readability) and each post on your blog will properly notify browsers, bots and users of its RSS feed. Certainly better than an obscure little link in the metadata. For a quick demo, view a post in Firefox and you will get two options whenever you click the Live Bookmark icon in the Address Bar. If you don’t, you’ve made a mistake somewhere and need to try again. Viewing your page source might make the error easier to find.






















Comments
Got something to say?
You must be logged in to post a comment.