I’ve noticed a lot of themes that don’t come with numbers on the blog’s comments.  This might not be such a bad thing if you don’t get very many comments, but if your blog does get comments it is probably a good idea to show off how many comments you get by numbering them.

Here are the steps you can take to easily add numbers to your WordPress theme’s comments section.

  1. First thing you will want to do is create a backup your comments.php file.
  2. Locate the comments.php file.
  3. Locate the code that starts the comment loop. It will look something like this:
    <?php if ( $comments ) : ?>
  4. Place this code immediately above the code in Step 3:
    <?php $i = 0; ?>
  5. Now locate the code that looks like this:
    <?php foreach ($comments as $comment) : ?>
  6. Placed this code immediately below the code in Step 5:
    <?php $i++; ?>
  7. Now use this code where you want to display your comment numbers:
    <span class="count">
    <?php echo $i; ?>
  8. Click Save.
  9. Now go to your stylesheet (style.css) and place this code anywhere on the stylesheet (probably best placed in the comments section):
    .count {
    padding: 10px;

You can adjust the stylesheet to fit your comment numbers into the placement and appearance that you want them to have.

Kyle Eslick is WordPress enthusiast who took his passion for WordPress to the next level in 2007 by launching WPHacks.com as a place to share hacks, tutorials, etc. Connect with Kyle on Twitter or Google+!

  • Neil Greenhorn

    Thanks very much, extremely useful!

  • Neil Greenhorn

    Really sorry for the double post, but I cannot find or anything like it in my comments.php file,

    Is there another way?


  • Hack WordPress


    I’m not sure if part of your post didn’t show up. You can’t find anything like which step?

  • Neil Greenhorn

    Sorry :) ,

    Just figured it out, dont know why most of my post was cut off!

    Everything is sorted,

    Thanks anyway.

  • http://www.internetmarketingfool.com Will

    How about just using an ordered list with each comment being a list item?

  • http://accidentalmommies.com Kim @ What’s That Smell?

    Thank you for this straightforward and simple explanation! I spent days with other sites making it so convoluted, your solution took about 30 seconds!

    Thanks again!

  • http://neowster.com Neowster

    Works like a charm. Thanks.

  • Pingback: Collection of WordPress Hacks

  • Pingback: Wordpress Hacks, Guides and Tricks | TechnoBuzz.net

  • Pingback: WordPress ?? ??? ??? tutorial

  • Christy


    I have giveaways to start drawing names for tomorrow and with most in the hundreds and one nearing 900, I def did NOT want to count through on each one to find the “right” one as per the random number selector, lol!


  • Pingback: 100+ Killer Wordpress Resources | Steffan Antonas’ Blog

  • Pingback: Top 30 Most Wanted Wordpress Tricks and Hacks | Make Money Blogging Experiment

  • guasman

    Hi, nice script! how can i make the same thing in posts?
    thanks in advance

  • Pingback: Top 10 Tutorials for Working with WordPress Comments

  • Pingback: Geek Week - This week jQuery tutorials, CSS3, & WordPress - PHP, XHTML, Web Design, Flash | JasonCypret.com

  • http://themejournal.com Aerotheme

    Extremely useful, but novices must have more explanation of using.

  • Pingback: Wordpress Updates » Blog Archive » Adding Comment Numbers to Posts

  • http://www.theblogshoppe.com Kathy Moore

    Perfect, exactly what I needed. Thank you so much for this tip!

  • Gaby

    Thank you so much! It’s what I needed!

  • http://west-penwith.org.uk/blog/ Rick

    Can you suggest how to do it in WP 2.7+ where all the meat of the comment display is done in wp_list_comments()? I have tried using a call back but the variable $i is not available there so I can’t increment nor display it.

    Even using OL (as demonstrated in the default theme) is no good when the comments are paged because every new page STARTS FROM 1 making it useless. Goodness knows what happens with threaded comments, I haven’t tried yet.

  • Derek

    My comments are currently setup to show the newest comments on top, instead of the default oldest first.

    Using this tutorial, it’s labeling my latest comment as #1,2,3 etc…

    So say I have 15 comments, it is showing my 15th comment as #1.

    Any easy way to reverse this order?

  • http://www.sebastienpage.com Sebastien

    Yeah! Thanks a lot. I’ve looked around for a solution to comment numbering for like 30 minutes! Clear and simple! Thanks again

  • Pingback: True Up » Archive » Linky Tuesday

  • http://moomettesmagnificents.com/blog Cindi @ Moomette’s Magnificents

    Thanks so much for this easy to follow explanation! I would have been looking for a plugin forever!

    It was so easy that even this Baby Boomer did it!

  • Pingback: 50+ Different Ways To Vastly Improve Your Wordpress Blog | Web Media Magazine

  • http://southerngirlreviews.com Kimberly

    Thanks so much! Super easy to follow and worked perfectly!

  • http://www.katzkatz.com shmolik katz

    doesnt work for me.
    where should u put no. 7 ?
    isnt there a plugin that can do that for low tech people, other then me ….

  • http://momsfocusonline.com/ Rajee


    My theme doesn’t have this code

    Sorry for the first comment.

    Please help.

  • matt

    thank you, i have a problem. somehow my comments-count does work blog-wide?? not only the comments of each post get counted from 1 to whatever, but the comments of all posts get counted! so it could be that i have a 10 posts on my blog, every post has a few comments, so the tenth post starts with comment number 35??? what i’m doing wrong?

  • http://theluckyladybug.org/ Cheryl F. (The Lucky Ladybug)

    Could you update this for the newer versions of WordPress? I’m using 2.8.4. The code in comments.php is totally different and it’s hard to figure out where to put what. Thank You!

  • Justin

    — *** SOLUTION *** —

    If you’re looking for a way to do that in WP 2.8.X, here’s how to:

    Go in your comment-template.php file in the wp-includes folder, and go to the “get_comments_number” function (approx. line 520).

    After “global $id;” (always in the “get_comments_number” function), add ” global $count; “.

    That’s it! Now all you have to do, in your index.php file (or whatever), add

    I’d recommand changing, in the “get_comments_number” function, the variable “$count ” to something else so a plugin doesn’t “interfere” with this global variable in the future. Per example, in my case, I renamed it to “$countcomments”. So it gives me this:

    function get_comments_number( $post_id = 0 ) {
    global $id;
    global $countcomments; /* First modification */
    $post_id = (int) $post_id;

    if ( !$post_id )
    $post_id = (int) $id;

    $post = get_post($post_id);
    if ( ! isset($post->comment_count) )
    $countcomments = 0; /* Second modification */
    $countcomments = $post->comment_count; /* Third modification */

    return apply_filters(‘get_comments_number’, $countcomments); /* Fourth modification */

    Now in my index.php, I just putted .

    Good luck!

    • http://www.jayworld.fr Jay

      Thanks Justin, but look like some words are missing in your comment oO. What do we have to add in the index.php file ? Thanks

    • charlie

      Your code for what to put in the index.php has been cut off. Can someone please edit so that we know how to show the number of the comment??? No use if the code isn’t there.

    • Janet

      Hi Justin

      Thanks for your post. I’m just getting started blogging but know I want a comment counter. So far per your instructions, I’ve amended the comments-template.php file according to your example (which if I am correct removes the $post id before the /*Fourth notification, right?).

      Anyway, as per a few other commenters, you seem to have left out some vital info re the index.php page and what to add in there? And do I need still need to amend the css stylesheet also?

      Could you pm me as your help would be greatly appreciated.
      Many thanks

      • Justin

        Just to let you know: I didn’t left anything out. I put everything that was needed, but WordPress cut off a large portion of the code since I didn’t put it in a “code” tag (didn’t know at the time). I thought the author of this article would take a few seconds to look at it and complete it since this isn’t that difficult, but I guess not.

        I’ll do a complete tutorial on my Blog pretty soon and post the link here.

        • Janet

          Many thanks. I look forward to checking that out.

          Kind regards


  • http://mx.anunciamex.com/ Sophie

    Thanks for the solution Justin

  • Pingback: How to Speed Up Your WordPress Blog by Having Less Plugins | WebTechWise

  • http://www.greenandchic.com/blog Carla | Green and Chic

    Thank you for these very easy instructions!

  • http://www.mommylivingthelifeofriley.com Melissa Cleaver

    This rocked! It was so easy! It actually worked right the first time! Many, many thanks!

  • Elizabeth @ MomCooks

    My theme doesn’t have . I’m using a WP 2.9.2 compatible theme. Any suggestions?

  • http://www.matiasgallipoli.com Matias

    awesome, it was very helpful :)

  • Joy

    That’s great! thank you for the tip

  • Joy

    That’s really a useful hack, appreciate

  • http://www.tatilyerlerim.biz/ tatil yerleri

    Thanks for the solution Justin

  • http://13770.org 13770

    I have is the same as Derk (http://wphacks.com/how-to-adding-comment-numbers-to-your-wordpress-theme/#comment-6253) my comments are currently setup to show the newest comments on top, instead of the default oldest first. How can I change the order, number 1 at the bottom and the most recent at the top.
    Thnak you

  • http://www.durianboy.com durian

    is this script still working for wp 3.2? update please!!

  • BJ

    Update the script this is old..

    Nobody use this WP version anymore..

  • http://www.d-nick.com Newman

    My solution for WP 3.2… I used the “Twenty Ten 1.0″ functions.php for example… in function twentyten_comment() (note: this function is called back from comments.php by wp_list_comments() to get template for comments and pingbacks). I just add a global variable ($GLOBALS['mycommentnumber']) and after that just increment by one:

    1st step: comments.php

    ‘twentyten_comment’ ) ); ?>

    2nd step: functions.php
    function twentyten_comment( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    switch ( $comment->comment_type ) :
    case ” :
    $GLOBALS['mycommentnumber']++; // first change ?>
    <li id=”li-comment-”>

    <div id="comment-” class=”comment-box” >

    not so complicated right? jajajajajajajajaja… that was useful for me, so I share it…

    • http://www.d-nick.com Newman

      Wrote again…
      1st step: comments.php

      'twentyten_comment' ) ); ?>

      2nd step: functions.php

      function twentyten_comment( $comment, $args, $depth ) {
      $GLOBALS['comment'] = $comment;
      switch ( $comment->comment_type ) :
      case '' :
      $GLOBALS['mycommentnumber']++; // increment value by one ?>
      <li id="li-comment-">

      <div id="comment-" class="comment-box" >

  • http://www.winedinedaily.com/ Wine Dine

    Thanks for the code snippets and steps.