Skip to content

Instantly share code, notes, and snippets.

@theMikeD theMikeD/example.php
Created Jan 12, 2016

Embed
What would you like to do?
How to assign a CPT icon to the dashboard
/**
* Sets the icon for a given CPT in the dashboard's "At a Glance" section.
* When registering a post type, adding ‘menu_icon’ => '' will result in the menu item
* being given the class "menu-icon-<cpt-slug>".
*
* Note that the dashicon used in the side menu is specified in the CPT declaration directly,
* but the dashboard icon is not.
* @param $cpt
* @param string $icon
*/
function cnmd_cpt_set_dashboard_glance_icon( $cpt, $icon='\f105') {
if ( $cpt == "" ) { return; }
?>
<style type="text/css">
#dashboard_right_now li.<? echo $cpt; ?>-count a:before { content: '<? echo $icon; ?>'; margin-left: -1px; }
</style>
<?php
}
add_action('admin_head', 'cnmd_cpt_set_tips_icon',1,0);
function cnmd_cpt_set_tips_icon() {
cnmd_cpt_set_dashboard_glance_icon( "tips",'\f118' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.