Add term of current custom post type to admin body class using admin_body_class

Question

I am trying to add the current custom post type term to the body class of my WordPress admin page. So when I am viewing an existing custom post type that has been assigned a term it will add that term to the body class.

I have found the following code but cannot get it to work for me:

add_filter( 'admin_body_class', 'rw_admin_body_class' );
function rw_admin_body_class( $classes )
{
    if ( 'post' != $screen->base )
        return $classes;

    global $post;
    $terms = wp_get_post_terms( $post->ID, 'product_cat', array( 'fields' => 'all' ) );
    $terms = wp_list_pluck( $terms, 'slug' );
    foreach ( $terms as $term )
    {
        $classes .= ' my_taxonomy-' . $term;
    }

    return $classes;
}

Any pointers on how to get this working?

0
moorewebx 7 months 2020-12-31T15:10:23-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse