Add a Comment Number/Link on Your WordPress Archives

I’m using the “Story” theme on my blog, and I love it except for one thing: there isn’t a link to my comments on my posts! I’ve had a look but I can’t figure it out myself, how can I add a comment link back on to all of my posts?
Leah

Great question, Leah! The actual process of adding this is very simple. The tricky part comes in telling you where to put the code. This is because every theme is designed so differently.

First, a warning:

This guide will lead you through editing your theme files. It involves PHP code, which is a bit dangerous to play with. If you enter incorrect PHP or even miss off a single bracket or semi-colon, you could break your site. I recommend editing through an FTP program instead of inside WordPress itself. And always take a backup of your theme code before changing it!

Where to put the code

Assuming you want to add this to your blog archive page (the homepage), you want to fist look in your theme’s index.php template. But then this is where it gets tricky. Some themes might include a separate file inside this one (like loop.php). So really, I can’t tell you exactly where to look because every theme is totally different! But I can give you a rough idea. You want to look around for this:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

This bit of code designates the start of The Loop. The Loop is the bit of repeating code for displaying all your posts. Once you’re inside The Loop, you’re good! If you want to look more specifically, you can look for where they output the title, which is done with:

<?php the_title(); ?>

How to display the comment number and link

Once you’ve found where to display the code, here’s the bit to actually do it:

<a href="<?php comments_link(); ?>"><?php comments_number( 'Leave a Comment', '1 Comment', '% Comments' ); ?></a>

This code does two things:

  • 1. It adds a link to your comment form for that post.
  • 2. It displays the number of comments.

If you want to edit the text you can. The comments_number() function has three parameters:

  • 1. The text that gets displayed when there are no comments. I have it set to Leave a Comment.
  • 2. The text that gets displayed when there is one comment (so ‘Comment’ isn’t plural). I have it set to 1 Comment.
  • 3. The text that gets displayed for any number of comments greater than 1 (so ‘Comments’ is plural). I have it set to % Comments. The % symbol is a placeholder for the actual number.

Hope this helps!

I’m sorry I can’t be more specific with where you place this code, Leah. But hopefully you’ll be able to find a good spot. 🙂

Photo of Ashley
I'm a 30-something California girl living in England (I fell in love with a Brit!). My three great passions are: books, coding, and fitness. more »

Don't miss my next post!

Sign up to get my blog posts sent directly to your inbox (plus exclusive store discounts!).

You might like these

4 comments

  1. Hmmm, I use the TweakMe theme and love it but there are a few things that I miss (coming from blogger) and one of them is a link to comments at the bottom of my post. I know that when I switched a lot of my readers were confused about where to find the comment button. Could I use this coding on the TweakMe theme?

    Trish recently posted: Bloggiesta – Fall 2014
    1. There is a link to comments at the top of the post. You want to add ANOTHER link at the bottom?

      You could use this code on Tweak Me but unless you make a child theme for yourself the code you add will be overwritten whenever the theme updates.

Recent Posts

    Random Posts