If you’re a WordPress user, you may be familiar with Custom Post Type, which allows you to create different types if content beyond just pages and posts. By default, Custom Post Type are display with generic icon in the WordPress admin menu, which can make if difficult to quickly distinguish between different content types.
To add a Dashicon to a Custom Post Type in WordPress, you can use the `menu_icon` parameter when registering the Custom Post Type.
Here’a an example:
function custom_post_type() {
$args = array(
'public' => true,
'label' => 'Custom Post Type',
'menu_icon' => 'dashicons-welcome-learn-more', // replace with desired Dashicon name
);
register_post_type( 'custom_post_type', $args );
}
add_action( 'init', 'custom_post_type' );
In the example above, we have registered a Custom Post Type called “custom_post_type” and set the `menu_icon` parmeter to `dashicons-welcome-learn-more`, which is the name if the Dashicon we want to use.
You can find a list of available Dashicons on the WordPress developer documentation website: https://developer.wordpress.org/resource/dashicons/
Simply replace `dashicons-welcome-learn-more` with the name of the Dashicon you want to use for your Custom Post Type.
Once you have added the menu_icon parameter to your Custom Post Type registration function and have selected a Dashicon, the icon will appear in the WordPress admin menu next to your Custom Post Type.