Adding an RSS Icon to the “Subscribe to Comment RSS feed” link in a WordPress Template

In working with my custom template for WordPress, I came across an unfortunate problem. It seems that the default output for the function post_comments_feed_link() displays a simple anchor tag with a link to the comment RSS feed.

I like to use the RSS Icon (feed-icon-14x14) to indicate that the feed is, in fact, an RSS feed. It’s easily recognized over just plain text. This is not possible in the default implementation, so I had to do some hacking.

To get the icon on my page, I had to do two things:

  • Edit the link-template.php file in /<your wordpress root>/wp-includes folder
  • Edit the style.css file

In link-template.php, search for the function named “post_comments_feed_link()”. Once you find that function, notice that the last line is:

echo apply_filters( ‘post_comments_feed_link_html’, “<a href=’$url’>$link_text</a>”, $post_id, $feed );

Simply change it to the following code:

echo apply_filters( ‘post_comments_feed_link_html’, “<a href=’$url’ id=’CommentRSSLink’>$link_text</a>”, $post_id, $feed );

This will give us an ID to hook up with in our CSS file.

In your styles.css file, simply add the following:

#CommentRssLink
{
    background-image: url(‘img/feed-icon-14×14.png’);
    background-repeat: no-repeat;
    background-position: 0;
    height: 14px;
    padding-left: 18px;
}

Make sure you have the correct feed-icon (you can get them here) in the <your/<template>/img folder.

You might also want to change your <your wordpress template root>/comments.php to change the wording of the text, as demonstrated below.

Here’s the final result:

rssSubscribeScreenCapture

All in all, I’m finding WordPress to be very easy to enhance and extend. This change allowed me to offer my readers an easy to recognize way to subscribe to my comments’ RSS feeds.

I hope this helps.

Advertisement

~ by Michael Earls on January 21, 2010.

2 Responses to “Adding an RSS Icon to the “Subscribe to Comment RSS feed” link in a WordPress Template”

  1. Is this for wordpress.com blogs? I need to change the rss icon in mine and cannot figure it out!! I have seen it elsewhere so know it is possible! Can you help me please? http://loveittoday.wordpress.com/

  2. I don’t know how to do it in WordPress.com blogs. I only know how to do it for hosted WordPress sites using a custom theme/template. Sorry.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.