Adding a Custom Post Type icon the right way

I think that now, nearly every WordPress developer knows how to create a custom post type (if you don’t, just download Easy Custom Post Type, a great plugin by the amazing Pippin Williamson), so i’m not going to explain how to create a custom post type, but i’m going to show you how to properly add a custom post type icon in the administration menu. The good point with this method is that you’ll get the really nice “mouse over” effect that renders the images from grey to colors.

If for example you create a custom post type called “portfolio”, here is the code to use to properly display the icon. This code must be placed in your functions.php inside your theme folder or in any page of your plugin (if you use this code in a plugin you will have to update the image path). Don’t forget to update the code depending on your custom post type attributes:

You can download here an image sample that fits the provided code.

4 responses to “Adding a Custom Post Type icon the right way”

    1. I am glad you like it!

  1. chris mccoy

    why not add it via the menu_icon variable when you create the post type?

    1. Using “menu_icon” doesn’t allow to have a different image for the “hover” state.

Leave a Reply