In today’s tutorial, we’ll show you how to use custom icon for custom post type you’ve added to your site. If you’re new to custom post types (CPT), you may first want to read our article on How to Create Custom Post Types in WordPress.
After you’ve successfully created a new CPT, you’ll see a default ‘pin’ icon is being used as the icon for your CPT menu. However, this can easily be changed with any other icon of your choice.
In this example, we’ll be using Dashicons icon font. Since this icon font is already comes with WordPress core since WordPress 3.8, it’ll make it easier for us to use any icon in the Dashicons icon font set. For complete icon font available for Dashicons, please see the Dashicons official page.
To use a custom icon, you’ve to to pass a string to menu_icon
argument. In this example, we’ll be using a star icon as the custom icon and from Dashicons official page, the class for this icon is 'dashicons-star-filled'
. Here’s an example to create a Portfolio CPT. As you can see in line 14, we paseed the menu_icon
argument with the class the the icon which is 'dashicons-star-filled'
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Here’s the result:
Furthermore, you may also use an image as the icon. For more information about this, please refer to the WordPress Codex page.
Kaloyan Banev says
I have done that through a modified plugin, but your way may be much easier. Though there is always a drawback on custom code, that might be overwritten by accident.