I found the following snippet will displays the number of Custom Post Types published in Dashboard’s At A Glance widget, like this:
Is there a way to turn that “81 Wrestlers” text to a link to the post types list. Here’s the code:
add_filter( 'dashboard_glance_items', 'custom_glance_items', 10, 1 );
function custom_glance_items( $items = array() ) {
$post_types = array( 'wrestler' );
foreach( $post_types as $type ) {
if( ! post_type_exists( $type ) ) continue;
$num_posts = wp_count_posts( $type );
if( $num_posts ) {
$published = intval( $num_posts->publish );
$post_type = get_post_type_object( $type );
$text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'your_textdomain' );
$text = sprintf( $text, number_format_i18n( $published ) );
if ( current_user_can( $post_type->cap->edit_posts ) ) {
$items[] = sprintf( '%2$s', $type, $text ) . "n";
} else {
$items[] = sprintf( '%2$s', $type, $text ) . "n";
}
}
}
return $items;
}
Here is the function that I use to display CPT in the “At a glance” widget
This make the text clickable as link. Hope this helps
Okay, so I used this code to only display “wrestler” post type & it worked. I mixed mine & Pieter Goosen’s code to get this out:
For all future occurrences, of adding custom post types to the ‘At a Glance’ box, the following code worked for me in WordPress 4.6.1. And it may work for others.
All credit goes to the following author
In code you posted I can’t really understand whats the point of:
I.E. if the current user can edit the post type do something, otherwise do same thing…
I guess you want to show the link to posts list if the current user can edit post type (just like WordPress does for pages and posts).
In that case your code becomes: