Skip to content

Instantly share code, notes, and snippets.

@corsonr
Created July 18, 2012 14:49
Show Gist options
  • Save corsonr/3136641 to your computer and use it in GitHub Desktop.
Save corsonr/3136641 to your computer and use it in GitHub Desktop.
Add a cpt icon the right way
<?php
/* ------------------------------------------------------------------*/
/* CUSTOM CPTs ICONS */
/* ------------------------------------------------------------------*/
// let's say you custom post type is : portfolio
add_action( 'admin_head', 'cpt_icons' );
function cpt_icons() {
?>
<style type="text/css" media="screen">
#menu-posts-portfolio .wp-menu-image {
background: url(<?php get_template_directory_uri(); ?>/images/portfolios-icon.png) no-repeat 6px -17px !important;
}
#menu-posts-portfolio:hover .wp-menu-image, #menu-posts-portfolio.wp-has-current-submenu .wp-menu-image {
background-position:6px 7px!important;
}
</style>
<?php } ?>
@helen
Copy link

helen commented Jul 24, 2012

You should probably use get_template_directory_uri() instead of bloginfo('template_url'), or the stylesheet equivalent (for child themes). Also, prefix your function :)

@corsonr
Copy link
Author

corsonr commented Jul 24, 2012

You're right Helen, Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment