0

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?

1

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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