WordPress’ announcement of the dashboard redesign inspired me to overhaul the way icons are done in SuperCPT (note: this addition will come in version 0.2, but you can use it now by cloning it from GitHub). After doing so, I realized I could easily parse the icon piece out as its own plugin! Enter Post Type Icons.
Post Type Icons is a radically simple plugin that gives you 361 wonderful icons courtesy of Font Awesome. The icons are font-based, so they’re vector in nature and look amazing no matter your screen’s DPI. Now your custom post types can have custom icons that look just like the core icons in every state (previously, it was difficult to get the hover/active state working quite right). This will be in the WordPress Plugin Repository as soon as it’s approved!
Instructions for use
- Install and activate the plugin as usual.
- Go to Tools → Post Type Icons and figure out which icon you want to use. Get the name from underneath it.
- In your theme or plugin, add the following bit of code (replacing “my-post-type” and “icon-name” as appropriate):
pti_set_post_type_icon( 'my-post-type', 'icon-name' );
pti_set_post_type_icon( 'event', 'calendar' );
Here’s what that looks like in a normal and active state:
- (alternate) Instead of calling the function
pti_set_post_type_icon()you can use the global variable
$pti_icons. This way you don’t have to check if the function exists, or risk a Fatal error. Simply declare
$pti_iconsan associative array with key => value pairs of post type => icon name. Here’s our event/calendar example again using the global variable:
$GLOBALS['pti_icons'] = array( 'event' => 'calendar' );
I hope you enjoy this plugin! At some point (hopefully on the sooner side) I’ll make a GUI for this. I also set it up to potentially allow many icon sets, so I’ll add more to the collection. What would you like to see in it?