Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

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.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted
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.

share|improve this answer
    
thanks for this - I've got it basically working. I can't seem to get the image size quite right. Hover isn't working either. Almost there. –  timshutes Dec 23 '12 at 5:07
    
ok - played around with the sprite and got it to work. Thanks again. marking as the answer. –  timshutes Dec 23 '12 at 5:15
    
Ops, forgot to mention, small image should be 16x16 (16x32 sprite - two images default and hover) and big 32x32 –  Ed T. Dec 23 '12 at 11:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.