WordPress Theme Developers Tip – Automatic Feed Links in 3.0

Version 3.0 of WordPress is due out soon, and theme developers are getting geared up to implement the new features. The new menu system has received much attention as it’s one of the biggest changes, besides the merge of the WPMU code, that most users will use.

One feature that I didn’t know exists until now is automatic feed links which will output all the different feed links to current page the users is on to the header. It was added in 2.8 but has been changed how it works for 3.0. For example on a single post page the main blog feed, and the single post comment feed links are added to the header allowing a user to easily subscribe to the either feed. Another is on a category archive page the feed for the main blog, as well as the feed for all posts in that category are added. So I’ve got this feature added to my Techozoic theme but to maintain backwards compatibility I though I would share the simple function I came up with.

To enable the automatic feed links it’s very simple, just use the add_theme_support function with the automatic-feed-links as the parameter like this into your functions.php.

if(function_exists('add_theme_support')) {
	add_theme_support('automatic-feed-links');
	//WP Auto Feed Links
}

It’s critical to test if a function exists before calling it to prevent errors.

function remove_feed_link(){
	global $wp_version;
	$default_feed_link = '<link rel="alternate" type="application/rss+xml" title="'. get_bloginfo('name'). ' RSS Feed" href="'. get_bloginfo('rss2_url') .'" />';
	if($wp_version < 3){ 
		if(function_exists(automatic_feed_links)){
			$output .= automatic_feed_links();
		} else {
			$output .= $default_feed_link;
		}
	}
	echo $output;
}
	add_action('wp_head', 'remove_feed_link');

Most theme authors include the default RSS feed in the header of their themes, but the new feature requires those links to be removed to work correctly. The trick to the automatic-feed-links is it’s a new 3.0 feature but the add_theme_support has exists since 2.9 so you can’t use the same check to disable your old feed links from the header. But what you can do is to check if the check the wp_version variable is less than 3, and if it is use either automatic_feed_links function or echo your own RSS link. Then you just add your function to be called with wp_head using add_action.

Futher Reference:
add_theme_support Codex Article

About Jeremy Clark

Small town IT worker with interests in all things technological and technical. Biggest interests are in web development especially the WordPress publishing platform and the community supporting it. Currently developing and maintain the free WordPress theme Techozoic. I'm also always available for hire.
This entry was posted in tips, wordpress and tagged , , . Bookmark the permalink.

8 Responses to "WordPress Theme Developers Tip – Automatic Feed Links in 3.0"

Leave a reply

Comments will be sent to the moderation queue.