Drafts, Pending and Scheduled in "At a Glance"
Adds draft, pending and scheduled post counts to the At a Glance dashboard box, linked to the filtered lists.
Opens WPIDE on
Code
add_filter( 'dashboard_glance_items', function ( $items ) {
if ( ! current_user_can( 'edit_posts' ) ) {
return $items;
}
$counts = wp_count_posts( 'post' );
$labels = array(
'draft' => array( '%s Draft', '%s Drafts' ),
'pending' => array( '%s Pending', '%s Pending' ),
'future' => array( '%s Scheduled', '%s Scheduled' ),
);
foreach ( $labels as $status => $forms ) {
$count = isset( $counts->$status ) ? (int) $counts->$status : 0;
if ( $count ) {
$items[] = sprintf(
'<a class="post-count" href="%1$s">%2$s</a>',
esc_url( admin_url( 'edit.php?post_status=' . $status ) ),
esc_html( sprintf( 1 === $count ? $forms[0] : $forms[1], number_format_i18n( $count ) ) )
);
}
}
return $items;
} );
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.