Here is how to add custom icons to your custom post types in the WordPress Admin area. These are also know as Dashicons.

For this we will be using icons found here: Dashicons

First, in the custom post type code you need to clear out the link to the icon like below:


function post_type_testimonials() {
	register_post_type( 'testimonials',
                array( 
				'label' => __('Testimonials'), 
				'singular_label' => __('Testimonials Item'),
				'_builtin' => false,
				'public' => true, 
				'show_ui' => true,
				'show_in_nav_menus' => true,
				'hierarchical' => true,
				'custom-fields' => false,
				'capability_type' => 'post',
				 'menu_icon' => '',
				'rewrite' => array(
					'slug' => 'testimonials',
					'with_front' => FALSE,
				),
				'supports' => array( 'title', 'editor', 'thumbnail' )  //other functions: excerpt, custom-fields, comments
					) 
				);
	register_taxonomy('testimonials_category', 'testimonials', array('hierarchical' => true, 'label' => 'Testimonials Categories', 'singular_name' => 'testimonials', "rewrite" => true, "query_var" => true));
}

add_action('init', 'post_type_testimonials');

See above where it says “menu-icon => ” “. That needs to be blank as shown above.

Next, you need to add css to the admin area to pull in the Dashicon. You can just add this CSS right below your code above.


function add_menu_icons_styles(){
?>%MINIFYHTML0104ecb6f12bc45b7d07277a6184c60643%

Copy the CSS from Dashicons to get the correct code for you icon.

That’s it!

Leave a Reply

Get in Touch

Please fill out the form below and we will get back to you ASAP