Use Native Dashicons for Custom Post Type Admin Menu

In the past I wrote how to register a custom post type in WordPress. If you go back to that post, you can see that I was using custom icon to use it as my Admin Menu icon for that custom post type. Even though such functionality gives you the option to get super creative and allows you to use any icon you want, it sometimes get you off track. Because all most all Admin Menu icons are native WordPress icon except yours one.

Good news is, since WordPress 3.8 “Dashicons” is being used on WordPress as their official Admin font icon. It also allows developers and users like you to use any icon for your custom post type. Generally, one can define Admin Menu icon for the custom post type using the “menu_icon” parameter within register_post_type function. However, now you can use Dashicons as your custom post type admin menu icon. Take a look at the sample snippet provided below.

<?php
add_action('init','my_post_type');
function my_post_type() {
   register_post_type('books', array('menu_icon' => 'dashicons-book'));
}
?>

This snippet should produce the following result. Take a look at the screenshot attached right underneath.

Using Native DashiconsThe Book Icon is from WordPress Native Dashicons Web Font.

Feel free to visit the developers page to explore more icons. I am
pretty sure that no matter whatever the type of your CPT is, you might find something or at least you would get pretty close to your desired one.

I also see the enormous potential of growth as far as the Dashicons is concern. You may also expect that the number of total icons might even increase on upcoming future, then again that’s just a prediction based on number of variables.

Today In History

  •  
  •  

Comment

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from Postable, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.