WordPress Theme Developers Tip – Automatic Feed Links in 3.0
By Jeremy Clark
tips, wordpress |
development, theme, wordpress | 2,400 views
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
Related posts:
- WordPress Theme Developers Tip – Adding Theme Menu
- WordPress Theme Developers Tip – Call Dynamic CSS the Right Way
- WordPress Theme Dev Tip – Dynamic Stylesheets
- WordPress Theme Options Framework Ver 2
- WordPress 2.7 Comment Callback Function




Towfiq I
Aug 10th 2010 @ 8:34 amThanks for the use of new automatic-feed-links
abdussamad
Nov 4th 2010 @ 10:23 amYour code appears to be incorrect. If the wordpress version is greater than or equal to 3.0 your code will still display the default link code instead of using the output of automatic_feed_links()
Ian V.
Dec 1st 2010 @ 10:49 pmI’m not sure if that’s causing my site to display comments rss instead of contents feed. I noticed it when I commented from a blog using a commentluv plugin. When I submitted by blog into a blog directory site, it’s also displaying comments feed instead of contents. You can check here http://www.topblogs.com.ph/details/22925.html
Joshua
Jan 25th 2011 @ 9:33 pmThanks! I found your post in a Google search. I was having an issue with getting a 404 on my comment feed, I guess because I don’t have comments allowed on my site at the moment so there was nothing to show. I used what I learned here to remove the comment feed from my header while keeping the main feed.
Grant
May 26th 2011 @ 3:46 amGreat article, good thing to learn a little about WordPress theme developer.
Arina
Sep 23rd 2011 @ 1:20 pmThanks. I just applied to my site, and it actually works!
Clara
Sep 26th 2011 @ 11:41 pmThanks for sharing the automatic feed links code. Now I know what to do.