如果您通过add\\u menu\\u page或add\\u submenu\\u page添加页面,并且只需要css,那么这些函数将返回一个挂钩,您可以使用load-$your\\u挂钩操作。使用上述挂钩,您只能在这个特定页面上加载css。例如:
add_action( \'admin_menu\', \'register_page\');
function register_page()
{
$my_hook = add_menu_page( \'tab title\', \'page title\', \'manage_options\', \'my-page-slug\', \'callback_function\', \'dashicons-cloud\', 1 );
add_action( \'load-\'.$my_hook, load_scripts );
}
function load_scripts ()
{
add_action( \'admin_enqueue_scripts\', \'enqueue_bootstrap\' );
}
function enqueue_bootstrap()
{
$path = plugins_url( \'my_plugin/inc/css/bootstrap.min.css\' ); //use your path of course
$dependencies = array(); //add any depencdencies in array
$version = false; //or use a version int or string
wp_enqueue_style( \'myplugin-bootstrap\', $path, $dependencies, $version );
}