您可以连接到admin_body_class
:
add_filter( \'admin_body_class\', \'set_admin_page_as_body_class\' );
/**
* Create a body class based on the current admin page.
*
* @param string $classes The current admin body classes.
* @return string
*/
function set_admin_page_as_body_class( $classes ) {
/**
* For safety, I always check for get_current_screen before I use it.
* May not be needed for how late `admin_body_class` is filtered.
*/
if ( ! function_exists( \'get_current_screen\' ) ) {
return $classes;
}
$screen = get_current_screen();
/**
* Build an array of the parts you want.
*
* $screen->base gives you the page pase, so "edit.php"\'s base is "edit"
* get_query_var: https://codex.wordpress.org/Function_Reference/get_query_var
*/
$vars = [
$screen->base,
get_query_var( \'post_type\' ),
get_query_var( \'post_status\' ),
// etc.
];
// array_filter will remove any "empty" elements.
$vars = array_filter( $vars );
$class = implode( \'-\', $vars );
// Don\'t add our class more than once.
if ( false !== strpos( $classes, $class ) ) {
return $classes;
}
$classes .= " {$class} ";
return $classes;
}
编辑:示例URL,
wp-admin/edit.php?post_status=trash&post_type=locations
将生成如下类
edit-locations-trash