Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Display Most Commented Posts in WordPress (2 Ways)

Highlighting the most commented posts on your WordPress site can help visitors find your best content and increase pageviews. It can also encourage further discussion among your readers.

On the WPBeginner blog, we have displayed the most commented posts and noticed a significant boost in traffic to our key articles. This approach encourages visitors to stay on the site longer and engage by leaving comments.

In this article, we will show you how to easily display the most commented posts in WordPress, step by step.

How to display most commented posts in your WordPress

Why Display the Most Commented Posts in WordPress?

Your most commented posts have very high levels of user engagement. By displaying your popular posts, you encourage new readers to join the discussion and spend more time on your WordPress website.

All of this together is a big boost of social proof for your site.

When your visitors stay on your site longer, you can convince them to read another post, join your email list, or make a purchase.

Plus, when new visitors leave a comment, they become part of the community. This can help you build trust with your readers over the long term.

That being said, let’s take a look at how to easily display your most commented posts in WordPress using 2 methods. You can click the links below to move to the section of your choice:

Method 1: Display Most Commented Posts With a Plugin in WordPress (Recommended)

There are many different WordPress popular post plugins that you can use to display your popular articles, but the simplest to use is MonsterInsights.

It’s the best analytics solution for WordPress, used by over 3 million websites. With this plugin, you can easily display your most commented posts anywhere on your website.

First, you need to install, activate, and set up MonsterInsights. For more details, see our beginner’s guide on how to install Google Analytics in WordPress.

Note: MonsterInsights has a free version, but we’re using the pro version for this tutorial since it includes the popular posts feature.

Upon activation, navigate to the Insights » Popular Posts page and then click the ‘Popular Posts Widget’ tab in the menu.

Popular post widget

On this screen, you will control the appearance of your most commented posts.

Simply select the ‘Theme’ that you want to use for your posts. The theme operates similarly to your WordPress theme and will control the overall design of the most commented posts widget.

There are a ton of other customization options on this screen as well.

For example, in the ‘Theme Preview’ meta box, you can display your most commented posts in a ‘Wide’ format below your content or a ‘Narrow’ format to the right of your content.

View theme preview

After that, you have more options for customizing the design.

For example, you can change the size and color of the title, icon, and background.

Customize widget design

MonsterInsights will automatically save any changes you make to your most commented post display settings.

Once you’ve finished customizing the appearance of your commented posts, it’s time to display your popular posts by comments.

In the ‘Sort By’ meta box, simply select the ‘Comments’ option.

Sort by comments

Next, scroll down and view more options to include and exclude posts.

There is also an option to include posts from specific categories in the popular post widget.

Include and exclude posts

MonsterInsights will automatically display your most commented posts.

You have a few different options for adding your popular posts to WordPress. You can choose manual or automatic placement.

If you choose ‘Automatic’ placement, then the plugin will add your most commented WordPress posts directly after the last paragraph of your blog posts.

Enable automatic placement

The other option is to display your most commented posts manually. If you select the ‘Manual’ option, then you can add the popular posts widget with a Gutenberg block or a shortcode.

To do this, open up a page or post where you want to display your most commented posts.

Once inside the content editor, just click the ‘+’ icon and select the ‘Popular Posts’ block.

Add popular post block

This will automatically add your most commented posts to your page.

Make sure you click the ‘Update’ or ‘Publish’ button to make your changes live.

Update and publish your changes

Now when your users visit the page, they will see your most commented posts displayed.

You can visit the website to see the most popular posts with comments in action.

View most popular posts preview

Method 2: Display Most Commented Posts Using Code

The second method involves adding code to your WordPress files.

However, there are some downsides to using this method. First, it involves adding code to WordPress, so it’s not beginner-friendly. It can cause serious problems with even a small error, so we recommend editing WordPress core files for advanced users.

Second, the code isn’t as optimized for performance as the MonterInsights plugin. This increases the server load and can slow down your website.

That being said, let’s take a look at how you can display the most commented posts in WordPress without a plugin.

Adding Code Snippet to functions.php File

You’ll want to add the code provided below to your functions.php file. We recommend doing this by using the WPCode plugin. It’s the safest and best way to add custom code to your WordPress blog.

First, you will need to install and activate the WPCode plugin. For more details, please see our guide on how to install a WordPress plugin.

Note: You can also use the free WPCode plugin, which has all the features you need to add this code.

Once activated, you can head to the Code Snippets » + Add Snippet page from your WordPress dashboard and select the ‘Add Your Custom Code (New Snippet)’ option.

How to show post excerpts using code

Next, you can add a name for your code snippet at the top of the page. After that, select ‘PHP Snippet’ as the code type from the dropdown menu on the right.

Now, just copy and paste this code into the ‘Code Preview’ box:

function wpb_most_commented_posts() { 
// start output buffering
ob_start();
?>
<ul class="most-commented">
<?php 
// Run WP_Query
// change posts_per_page value to limit the number of posts
$query = new WP_Query('orderby=comment_count&posts_per_page=10'); 
  
//begin loop
while ($query->have_posts()) : $query->the_post(); ?>
  
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> <span class="wpb-comment-count"><?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></span></li>
<?php endwhile; 
// end loop
?>
</ul>
<?php
  
// Turn off output buffering
 $output = ob_get_clean(); 
  
//Return output 
return $output; 
}
// Create shortcode
add_shortcode('wpb_most_commented', 'wpb_most_commented_posts'); 
  
//Enable shortcode execution in text widgets
add_filter('widget_text', 'do_shortcode');
Copy and paste code snippet

Once that’s done, simply click the toggle to make the code ‘Active’ and then press the ‘Save Snippet’ button at the top.

For more details, please check out our beginner’s guide to pasting snippets from the web into WordPress.

The code will run a database query and fetch 10 posts ordered by the highest comment count. Then, it uses output buffering to create a shortcode you can use to display the posts.

The last line of the code creates a shortcode that you can use in your posts, pages, and widget areas.

To display your popular posts, all you need to do is add the following shortcode to your WordPress site.

[wpb_most_commented]

For more details, see our beginner’s guide on how to add a shortcode in WordPress.

If you want to add thumbnails next to your post titles, then add the following line of code right after <li> tag in the code above.

<?php the_post_thumbnail(array(40,40)); ?>

This code will define the custom size for the post thumbnail images. You can adjust the size to meet your needs.

Style Your Most Commented Posts using CSS

Once you’ve done that, you can style how your most commented posts will be displayed.

To do this, you can modify the .most-commented and .wpb-comment-count CSS classes in your WordPress theme’s stylesheet.

You can use the following CSS to get started:

.most-commented li { 
border-bottom:1px solid #eee; 
padding-bottom:3px; 
} 
.most-commented li :after { 
clear:both;
} 
.most-commented img { 
padding:3px;
margin:3px;
float:left;
}
.wpb_comment_count a, .wpb_comment_count a:active, .wpb_comment_count a:visited, .wpb_comment_count a:hover { 
color:#FFF;
}

To add CSS to your website theme’s stylesheet, you can use WPCode.

Simply go to Code Snippets » + Add Snippet from your WordPress dashboard and select the ‘Add Your Custom Code (New Snippet)’ option.

How to show post excerpts using code

Next, enter the CSS code under the Code Preview area and add a title for your snippet.

Then, make sure that you click the Code Type dropdown menu and select the ‘CSS Snippet’ option.

Add CSS code snippet

When you’re done, don’t forget to switch the toggle to ‘Active’ and then click the ‘Save Snippet’ button at the top.

For more details, see our guide on how to easily add custom CSS to your WordPress site.

Bonus: Display Popular Posts By Views in WordPress

If you don’t want to show the blog posts with the most comments, then you may wish to display the articles that are trending and have the most user views on your website.

Doing this can increase conversions and help visitors discover the content their fellow readers like the most.

WPBeginner's trending and popular posts

To display popular posts by views, you can use MonsterInsights and its Dimensions addon. For more information, see our MonsterInsights review.

Upon activation, visit the Insights » Settings page from the WordPress dashboard and switch to the ‘Conversions’ tab. Here, click the ‘Add New Custom Dimension’ button.

This will open a dropdown menu, from which you must select ‘Post Type’. Now, MonsterInsights will start tracking your blog post performance.

Selecting post type as a custom dimension in MonsterInsights

Next, visit the Insights » Popular Posts page from the WordPress dashboard and switch to the ‘Popular Posts Widget’ tab.

Here, you can configure the layout style, background color, and text color for your widget. Once you have done that, scroll down to the ‘Sort By’ section and select the ‘Curated’ option.

After that, enable the ‘Add Top 5 Posts from Google Analytics’ option below.

Some of the popular posts widget's behavior settings in MonsterInsights

You can now embed the ‘Popular Posts’ block on the page or post where you want to display the most popular posts by views. For details, see our tutorial on how to display popular posts by views in WordPress.

We hope this article helped you display the most commented posts in WordPress. You may also want to see our tutorial on how to turn off comment notifications in WordPress and our expert pick of the best related posts plugins for WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

6 CommentsLeave a Reply

  1. Syed Balkhi

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Ralph

    This article is a gem for bloggers seeking to enhance their website engagement! Displaying the most commented posts is a brilliant strategy to boost overall pageviews.

    I used to display 5 most popular posts by views, but that didn’t do the trick.
    Most popular is not as interesting as post with comment counter that shows 100+ comments.
    Most popular can be meh, but the most commented? People are curious what others have to say.

    Thanks for 2 ways of doing this. I tried code, but that didn’t work so I will try plugin. I see it has much more things to offer.

  3. Jiří Vaněk

    Thank you for the snippet. I’d like similar functionality on my friend website as well, but I didn’t want to go down the path of adding another plugin that would consume memory. I use WPCode for snippets, so this snippet will come in very handy.

  4. Nishant Nanda

    Loved this post and one question that do we have to add CSS code after the commented code in functions.php

  5. Rohit Palit

    Great post. It was much needed. Love your simplistic style of explanation. :)

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.