WordPress RSS Feed Link Custom Coding | WordPress RSS Feed Link Hard Coding

2 CommentsRSS Site FeedAuthor: AITpro Admin
Published: August 9, 2010
Updated: September 29, 2010

The orginal question was regarding how to custom code RSS feed links and possibly how to add a link from the RSS feed itself to another page or post.

You can hard code WordPress RSS feeds directly in your WordPress Theme templates > index.php, archive.php and single.php (and any other templates). You can also add an RSS feed link in a post. An RSS feed is basically just a link with the word “feed” added to the end of the link. Using my site as the example >>> http://www.ait-pro.com/aitpro-blog/feed

So the PHP code you would add to your WordPress templates would be:

<a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('RSS Site Feed'); ?>">RSS Feed</a>

If you want to create an RSS feed link to a specific WordPress category or post you would have to use a regular HTTP link like the example I added above instead of PHP.

The steps to add the hard code to your WordPress templates are you would open one of your WordPress templates and find the location in the template where you want to add your RSS feed link. You should see div tags in your template, which are basically “dividers” – div tags define the sections of a Web page. So you will add your RSS code wherever you want it within a certain div tag section so that your RSS feed link will display where you want it to display on your web pages.

ADDITIONAL ADDED INFO:
If you want to add an image to your RSS feed link and be able to control the image properties with CSS you would add this code:

<span class="rss2"><a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('RSS Site Feed'); ?>"><img src="http://www.ait-pro.com/aitpro-blog/wp-content/themes/AITpro/images/rss_icon.png" alt="RSS Site Feed" title="RSS Site Feed" /></a></span>

I created a CSS class called rss2, put it in a span and created a custom image for the RSS feed link.

The CSS code: (Theme’s style.css)

.rss2 {
 border:none;
 float:right;
 width:27px;
 height:31px;
 padding:3px 2px 0px 0px;
 }
.rss2 a {border:none;}
.rss2 a:hover {border:none;}

At some point I’ll add an actual hover effect.

Also I wanted the RSS link and image to be on the right top of my post pages in the same div as the Title div so I just added this code within the title div and then used the float:right CSS code to float the link and image to the right side of the title div.

In response to your additional info. There is no big mystery about an RSS feed link so you would just use the http link that shows up in the URL address window of your browser and then add that http link to the WordPress template that you want or the specific page that you want. Anytime you are trying to do something specific to only one particular post / page in WordPress you need to create a custom template for that particular post or page. If you create a custom template and want to link a post in a category then you will have to use a plugin like the Page Links to WordPress plugin to redirect it permanently (301 Redirect) to your custom template page.

Oh and 1 last thing just incase you are trying to literally add an additional link or Ad to your feed. You can modify the core WordPress RSS files, but that is not a good idea. The best method is to add code like this below to your Theme’s functions.php file:

<?php
function insert_a_link_or_Ad($content) {
$content = $content.'<br /><a href="http://www.yourwebsite.com">Your link text</a><br />';
return $content;
}
add_filter('the_excerpt_rss', 'insert_a_link_or_Ad');
add_filter('the_content_rss', 'insert_a_link_or_Ad');
?>