# Content Statistics Widget

> Summarizes published, draft and scheduled items for every post type, plus media files and comments awaiting moderation.

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

## Code

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

    wp_add_dashboard_widget( 'wpide_content_stats', 'Content Statistics', function () {
        echo '<table class="widefat striped"><thead><tr><th>Type</th><th>Published</th><th>Drafts</th><th>Scheduled</th></tr></thead><tbody>';
        foreach ( get_post_types( array( 'show_ui' => true ), 'objects' ) as $type ) {
            if ( in_array( $type->name, array( 'attachment', 'wp_block', 'wp_navigation', 'wp_template', 'wp_template_part' ), true ) ) {
                continue;
            }
            $count = wp_count_posts( $type->name );
            printf(
                '<tr><td><a href="%1$s">%2$s</a></td><td>%3$d</td><td>%4$d</td><td>%5$d</td></tr>',
                esc_url( admin_url( 'edit.php?post_type=' . $type->name ) ),
                esc_html( $type->labels->name ),
                isset( $count->publish ) ? (int) $count->publish : 0,
                isset( $count->draft ) ? (int) $count->draft : 0,
                isset( $count->future ) ? (int) $count->future : 0
            );
        }
        echo '</tbody></table>';

        $media    = array_sum( (array) wp_count_attachments() );
        $comments = wp_count_comments();
        printf( '<p>Media files: <strong>%1$s</strong> &middot; Comments awaiting moderation: <strong>%2$s</strong></p>', esc_html( number_format_i18n( $media ) ), esc_html( number_format_i18n( $comments->moderated ) ) );
    } );
} );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Content Statistics 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/
