The WordPress dashboard includes a handy widget that displays some brief information about your site at a glance – rather creatively, it’s titled ‘At a Glance’. By default it shows you the number of posts, pages and comments on your site allowing you to click through to edit each of those sections if you have the right permissions.
When building a plugin with a custom post type, it’s often a good idea to add your post type to the widget as it makes things more accessible and generally more user friendly for everyone. Using the snippet below you can add any number of custom post types to this widget (I’ve also included some useful CSS to customise the icons displayed):
All you need to do is replace the $post_types
array with an array of the post types that you want to add to the widget. You’ll see that the snippet includes a security check so that only users with permission to edit each post type will be able to click through and do so.
The CSS will replace the circle with the same icon that the Posts post type uses. You can replace the content
attribute there with one of the icons from this set – just select your icon and copy the relevant CSS from the link provided.
Leave a Reply