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.

Within admin pages can one target specific pages based on their body class, as in the front end? For example I created a custom post type and would like to target its add and edit pages for some CSS tweaks. How do I go about that?

share|improve this question
    
The front end pages can be targeted as indicated here: codex.wordpress.org/Function_Reference/body_class I am looking for the admin counterpart for this. –  drtanz Aug 21 '12 at 8:25
add comment

1 Answer

up vote 1 down vote accepted

Found this, but it really should be in WordPress Core:

// Body class for admin
// http://www.kevinleary.net/customizing-wordpress-admin-css-javascript/
function base_admin_body_class( $classes )
{
    // Current action
    if ( is_admin() && isset($_GET['action']) ) {
        $classes .= 'action-'.$_GET['action'];
    }
    // Current post ID
    if ( is_admin() && isset($_GET['post']) ) {
        $classes .= ' ';
        $classes .= 'post-'.$_GET['post'];
    }
    // New post type & listing page
    if ( isset($_GET['post_type']) ) $post_type = $_GET['post_type'];
    if ( isset($post_type) ) {
        $classes .= ' ';
        $classes .= 'post-type-'.$post_type;
    }
    // Editting a post type
    $post_query = $_GET['post'];
    if ( isset($post_query) ) {
        $current_post_edit = get_post($post_query);
        $current_post_type = $current_post_edit->post_type;
        if ( !empty($current_post_type) ) {
            $classes .= ' ';
            $classes .= 'post-type-'.$current_post_type;
        }
    }
    // Return the $classes array
    return $classes;
}
add_filter('admin_body_class', 'base_admin_body_class');
share|improve this answer
    
Also take a look at deluxeblogtips.com/2012/01/get-admin-screen-information.html –  drtanz Aug 21 '12 at 9: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.