Adding custom styling to WordPress custom post types admin screens

My WordPress projects usually end up using at least 3 custom post types, sometimes more than 10. Together with some extra admin screens (from external plugins[1]), the admin menu gets cluttered. All the various edit post admin screens can look very similar to the untrained eye.

What to do about!? Well, I’m not a designer, but I can certainly kick-start things by providing inspiration to my colleagues. What I need is some way of boldly showing them that we can add some styling to specific post type admin screens.

add_filter( 'admin_body_class', 'tcb_custom_post_type_body_class' );
function tcb_custom_post_type_body_class( $classes ){
  global $post;

  $post_class = get_post_type( $post->ID ) . '_admin';
  if( is_array($classes) ):
    $classes[] = $post_class;
  else :
    $classes .= " {$post_class}";
  endif;

  return $classes;
}

That will add a class to the page’s body tag, which can be targeted with CSS. Here is a rather pathetic example for my albums and artists post types:

.albums_admin{
  background-color: #0f0;
}
.artists_admin{
  background-color: #f00;
}

Good luck with that!