Skip to content

Instantly share code, notes, and snippets.

@szbl
Last active December 15, 2015 07:49
Show Gist options
  • Save szbl/5226783 to your computer and use it in GitHub Desktop.
Save szbl/5226783 to your computer and use it in GitHub Desktop.
Adding a custom post type icon from the CPT icon set. Icons and code from Randy Jensen: http://randyjensenonline.com/thoughts/wordpress-custom-post-type-fugue-icons/ WordCamp San Diego 2013
<?php
/*
Add custom icon with grayscale to color activation states.
Makes you more like core.
We're assuming this is included in your core plugin file
and the icon cpt-icon.png is in the same directory.
So, if this file were /wp-content/plugins/my-plugin/plugin.php
the icon file would be /wp-content/plugins/my-plugin/cpt-icon.png
Be sure to check out these great icons and original source:
http://randyjensenonline.com/thoughts/wordpress-custom-post-type-fugue-icons/
*/
add_action( 'admin_head', 'szbl_cpt_icons' );
function szbl_cpt_icons()
{
$post_type = 'szbl-post-type-slug';
?>
<style type="text/css" media="screen">
#menu-posts-<?php echo $post_type; ?> .wp-menu-image
{
background: url(<?php echo plugins_url( '/cpt-icon.png', __FILE__ ); ?>)
no-repeat 6px -17px !important;
}
#menu-posts-<?php echo $post_type; ?>:hover .wp-menu-image,
#menu-posts-<?php echo $post_type; ?>.wp-has-current-submenu .wp-menu-image
{
background-position:6px 7px!important;
}
</style>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment