Search for the Article

How to Add Icons for Custom Post Types in WordPress

To change the icon of a service in your custom post type, you need to modify the code that registers the post type and adds the meta box for selecting the template.

Here's how you can change the icon for the "Services" custom post type:

  1. Choose a Dashicon: WordPress comes with a set of built-in icons called Dashicons. You can choose an icon from the Dashicon library that best represents your service. You can view the Dashicons library here: https://developer.wordpress.org/resource/dashicons/

  2. Update the 'menu_icon' parameter: In the code that registers the "Services" custom post type, find the 'menu_icon' => 'dashicons-admin-tools' line. Replace 'dashicons-admin-tools' with the name of the Dashicon you want to use for your services. For example, if you want to use the "star-filled" icon, you would use 'dashicons-star-filled'.

Here's the modified code:



function custom_register_services_post_type() {
    register_post_type('services', array(
        'labels' => array(
            'name' => 'Services',
            'singular_name' => 'Service',
        ),
        'public' => true,
        'has_archive' => true,
        'supports' => array('title', 'editor', 'thumbnail', 'page-attributes', 'custom-fields'),
        'menu_icon' => 'dashicons-star-filled', // Change this line to the desired Dashicon name
    ));
}
add_action('init', 'custom_register_services_post_type');