Created
January 12, 2016 22:29
-
-
Save theMikeD/f30d891f9a2f98f25ddb to your computer and use it in GitHub Desktop.
How to assign a CPT icon to the dashboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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