# Most Commented Posts Widget

> Lists the posts with the most approved comments on the dashboard, a quick read on what sparks conversation.

- Type: PHP
- Runs: Admin only
- Category: [Dashboard](https://wpide.com/library/category/dashboard/)
- Tags: dashboard, widget, comments
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/most-commented-posts-widget/

## Code

```php
add_action( 'wp_dashboard_setup', function () {
    if ( ! current_user_can( 'edit_posts' ) ) {
        return;
    }

    wp_add_dashboard_widget( 'wpide_most_commented', 'Most Commented', function () {
        $posts = get_posts( array(
            'post_type'   => 'post',
            'numberposts' => 8,
            'orderby'     => 'comment_count',
            'order'       => 'DESC',
        ) );

        echo '<ol>';
        foreach ( $posts as $item ) {
            if ( ! $item->comment_count ) {
                continue;
            }
            printf(
                '<li><a href="%1$s">%2$s</a> <span style="color:#646970">(%3$s)</span></li>',
                esc_url( get_permalink( $item ) ),
                esc_html( get_the_title( $item ) ),
                esc_html( number_format_i18n( $item->comment_count ) )
            );
        }
        echo '</ol>';
    } );
} );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Most Commented Posts Widget" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
