使用admin_body_class
具有全局post\\u id和get_current_screen
功能:
add_filter(\'admin_body_class\', \'wpse_320244_admin_body_class\');
function wpse_320244_admin_body_class($classes) {
global $post;
// get_current_screen() returns object with current admin screen
// @link https://codex.wordpress.org/Function_Reference/get_current_screen
$current_screen = get_current_screen();
if($current_screen->base === "post" && absint($post->ID) === 8) {
$classes .= \' home-admin-area\';
}
return $classes;
}
还可以使用$pagenow变量。这种方式似乎更可取,因为
get_current_screen()
在某些情况下可能未定义:
add_filter(\'admin_body_class\', \'wpse_320244_admin_body_class\');
function wpse_320244_admin_body_class($classes) {
global $post, $pagenow;
// $pagenow contains current admin-side php-file
// absint converts type to int, so we can use strict comparison
if($pagenow === \'post.php\' && absint($post->ID) === 8) {
$classes .= \' home-admin-area\';
}
return $classes;
}