The dashboard_glance_items WordPress PHP filter allows you to modify the array of extra elements displayed in the ‘At a Glance’ dashboard widget.
Usage
add_filter('dashboard_glance_items', 'my_custom_glance_items'); function my_custom_glance_items($items) { // your custom code here return $items; }
Parameters
$items
(string[]): Array of extra ‘At a Glance’ widget items.
More information
See WordPress Developer Resources: dashboard_glance_items
Examples
Add a custom post type to the ‘At a Glance’ widget
add_filter('dashboard_glance_items', 'add_custom_post_type_to_glance'); function add_custom_post_type_to_glance($items) { $post_type = 'my_custom_post_type'; $num_posts = wp_count_posts($post_type); $text = _n('%s Custom Post', '%s Custom Posts', $num_posts->publish, 'textdomain'); $text = sprintf($text, number_format_i18n($num_posts->publish)); $items[] = "<a href='edit.php?post_type=$post_type'>$text</a>"; return $items; }
Add a custom taxonomy to the ‘At a Glance’ widget
add_filter('dashboard_glance_items', 'add_custom_taxonomy_to_glance'); function add_custom_taxonomy_to_glance($items) { $taxonomy = 'my_custom_taxonomy'; $num_terms = wp_count_terms($taxonomy); $text = _n('%s Custom Term', '%s Custom Terms', $num_terms, 'textdomain'); $text = sprintf($text, number_format_i18n($num_terms)); $items[] = "<a href='edit-tags.php?taxonomy=$taxonomy'>$text</a>"; return $items; }
Add the number of users to the ‘At a Glance’ widget
add_filter('dashboard_glance_items', 'add_users_to_glance'); function add_users_to_glance($items) { $user_count = count_users(); $text = _n('%s User', '%s Users', $user_count['total_users'], 'textdomain'); $text = sprintf($text, number_format_i18n($user_count['total_users'])); $items[] = "<a href='users.php'>$text</a>"; return $items; }
Add the number of approved comments to the ‘At a Glance’ widget
add_filter('dashboard_glance_items', 'add_approved_comments_to_glance'); function add_approved_comments_to_glance($items) { $comments_count = wp_count_comments(); $text = _n('%s Approved Comment', '%s Approved Comments', $comments_count->approved, 'textdomain'); $text = sprintf($text, number_format_i18n($comments_count->approved)); $items[] = "<a href='edit-comments.php'>$text</a>"; return $items; }
Add a custom statistic to the ‘At a Glance’ widget
add_filter('dashboard_glance_items', 'add_custom_stat_to_glance'); function add_custom_stat_to_glance($items) { $custom_stat = 42; // replace with your custom statistic $items[] = "<span>$custom_stat Custom Statistic</span>"; return $items; }