Content Statistics Widget
Summarizes published, draft and scheduled items for every post type, plus media files and comments awaiting moderation.
Opens WPIDE on
Code
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> · Comments awaiting moderation: <strong>%2$s</strong></p>', esc_html( number_format_i18n( $media ) ), esc_html( number_format_i18n( $comments->moderated ) ) );
} );
} );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.