How can I use a different default admin menu icon for custom post type?

For a particular custom post type I’m setting, I simply want to change the default icon to the wordpress pages icon (menu-icon-page).

I know I could upload my own pages icon and point to it, but can I just tell wordpress to use the default pages icon?

Read More

Here’s what I’m using

register_post_type( 'intranet-pages',  // creates the custom admin panel
    array(
      'labels' => array(
       ...
        'menu_icon' => menu-icon-page,

I’ve tried to do different variations and can’t figure it out. Thoughts? If I have to upload my own I will. Just don’t want to duplicate if it’s not necessary. Thanks!

UPDATE: According to this, it can’t be done: How to use a WordPress’ existing admin icon? At least not this simply. Does this still apply? Looks like I’ll be uploading it.

UPDATE 2: See below for a more elegant solution. Simply uploading and using menu_icon => doesn’t allow for the nice hover effects or the 32px icon on the edit screen.

Related posts

Leave a Reply

1 comment

  1. add_action( 'admin_head', 'custom_post_type_icon' );
    
    function custom_post_type_icon() {
        ?>
        <style type="text/css" media="screen">
        #menu-posts-intranet-pages .wp-menu-image {
            background: url("PATH TO SMALL ICON") no-repeat 6px 6px !important;
        }
    
        #menu-posts-intranet-pages:hover .wp-menu-image, #menu-posts-intranet-pages.wp-has-current-submenu .wp-menu-image {
            background-position:6px -16px !important;
        }
    
        #icon-edit.icon32-posts-intranet-pages {background: url("PATH TO BIG ICON") no-repeat;}
        </style>
        <?php
    }
    

    This way is much better I believe as it also allows to add hover effect and change big icon as well. Add this piece of code and it should work. Just don’t forget to change icon url path.