WordPress: How to Auto Expand Comments by Default

Just a little gripe I have with some of the WordPress themes created by some of those amazing designers out there. Some theme designers forget to provide the option to have the comment dialogue box auto expand at the end of articles. Not a problem when there’s a button stating “add comment here” but it is a problem when there isn’t such a button or when busy visitors are too much in a rush to look for such a button. Think about it, do you look for a comment box or do you look for a “add comment” button?

After a little bit of searching I found the code edits needed to make the comment box always visible for WordPress articles; and I must say thank you to Sheila Hoff for posting the solution in the WordPress support forum (I’ve linked to your homepage in gratitude).

Here’s what you need to do to automatically expand WordPress comments:

  1. Go to your Dashboard, find where it says “Appearance” in the sidebar on the left-hand-side then select “Editor”
  2. On the right-hand-side of the newly opened page, you will see a list of files; select the one that says “Main Index Template” or “index.php”
  3. Look for a line of text that reads
    <?php get_header(); ?>

    and add

    <?php $withcomments = 1 ?>

    onto a new line below it

  4. Now check through the page for any line of text that might say
    <?php comments_template(); ?>

    If it isn’t present then find

    <?php endwhile; else: ?>

    and above it, on a line of its own, add

    <?php comments_template(); ?>

The top of the edited code should now look similar to:

<?php get_header(); ?>
<?php $withcomments = 1 ?>

And somewhere toward the bottom it will then look like

<?php comments_template(); ?>
<?php endwhile; else: ?>

You will find it easier to search “index.php” if you copy it into a text editor, press ctrl+f then type your search terms.

Comments

  1. Nice brief and this enter helped me alot in my college assignement. Gratefulness you for your information.

  2. I’m looking for how to autoexpend my comments. Now, your blog really help what I want. Thanks. Great content.

  3. Should this work with wordpress 3.0?
    Thank you

  4. It doesn’t work with 3.0. Do you have any suggestions?

  5. Very nice post thanks for sharing, just what I was looking for. Made the changes and was up and running in minutes.

  6. Hi,
    I’ve applied your tip to WP 3.0.1 with the default twentyten theme.
    It’s index.php has no at the bottom anymore, but it ‘kind of works’ when you add the below get_header and put between the get_sidebar and get_footer.

    The only ting is that now it seems to randomly (I just don’t see the pattern yet), show a “Leave A Reply” field under some posts and not others. All posts with comments get the reply field, but also some others without comments.

    It takes too much space on the page, so it ‘kind of works’.

    Thanks for your tip! I’m glad I’ll be able to shape it without another plugin.

    • some code got filtered out of my post:
      no php endwhile at the bottom.
      when you add the withcomments=1 below get_header and leave away the comments_template part near the bottom, I get the best results.

      It’s still not an ideal solution:
      -The comments indent not enough, which makes them look too much like a post, instead of comment.
      -Huge empty “Leave a Reply” fields. While some is desired to encourage discussion, this is ott.

      If you have any ideas, please let us know.

    • Hi Martinex. I’m actually looking at your site right now. I like it. Thank you for introducing me to it.

      Re the comments box: does the same happen when you use a different theme? I’m not sure why the the “Leave a Reply” shows under some posts and not others. I would need to test the tip on one of my test sites to work it out. For the comment box’s size and position, I would edit the theme’s CSS and HTML/PHP to move and resize the comment box to your desired place.

      Thank you for your feedback Martinex.

  7. Works. In my case the there is no “else” piece.
    Instead of I got . I searched for “endwhile” and found it. Thanks a lot.

  8. Nice one :) Seems silly for this not to be default. Now my hoards of non traffic will be able to see the comments box!

  9. I looked all over for this, thank you so much for posting it, really appreciate it

  10. Thank you and Sheila!

    KC de Cali

  11. not working with cordobo green theame

  12. Thanks for the codes, it works to my site. Steps are easy to follow and understand. Well-done.

  13. Do it works to any version of wordpress?

  14. It regularly amazes me precisely how website owners for example your
    self can find enough time and the commitment to carry on making terrific
    blog posts.

  15. I appreciate you taking the time to create this publish. It has been extremely helpful to me indeed. Appreciate it. http://www.mydietarystore.info

  16. It’s challenging to find knowledgeable folks on this topic, but you sound like you know what you’re talking about! Thanks

  17. Amanda Thomas says:

    Many thanks for sharing these instructions! <3

  18. what if neither line of text from step 4 is present? this is with iribbon pro

  19. what if neither line of text is present from step 4? im using i ribbon pro

  20. Great! very good explaination. I searched for this in all forums about wordpress, but all commend pointed to an other comment, which pointed to a other forum etc.

    After an half hour google-ing I’ve found this and it’s exactly what i needed.

    Thank you!

  21. Thank you so much for this! It worked great! THANK YOU, THANK YOU for posting this!

  22. Could you please repost what the code should now look like? I tried your solution and it “broke” my blog. Fortunately, I remembered what the code said before I edited it, and got it back. Thanks.

    • It shouldn’t have broken the blog unless the code already exists within your theme. Double-check your theme’s settings; you might not need additional code :)

Leave a Reply

All original content on these pages is fingerprinted and certified by Digiprove
Clashing TinyMCE Editor Background
Text Manipulation FAQ
Loading

Invite Friends to ‘JournalXtra’

Supercharge your web design skills with JournalXtra

Buy me lunch!

I'm a cheap date. Where else can you buy lunch for a couple of dollars?

I accept Bitcoin too!

Categories

Dynamik Website Builder
WPMU DEV - The WordPress Experts
StudioPress Theme of the Month