我在管理栏菜单中添加了一个菜单,但它的样式不起作用;看起来有默认样式
<style>
.my_menu_item_class{
color:red;
background: yellow;
}
</style>
<?php
add_action(\'admin_bar_menu\', \'add_toolbar_items\', 100);
function add_toolbar_items($admin_bar){
$admin_bar->add_menu( array(
\'id\' => \'my-item\',
\'title\' => \'My Item\',
\'href\' => \'#\',
\'meta\' => array(
\'title\' => __(\'My Item\'),
),
));
$admin_bar->add_menu( array(
\'id\' => \'my-sub-item\',
\'parent\' => \'my-item\',
\'title\' => \'My Sub Menu Item\',
\'href\' => \'#\',
\'meta\' => array(
\'title\' => __(\'My Sub Menu Item\'),
\'target\' => \'_blank\',
\'class\' => \'my_menu_item_class\'
),
));
$admin_bar->add_menu( array(
\'id\' => \'my-second-sub-item\',
\'parent\' => \'my-item\',
\'title\' => \'My Second Sub Menu Item\',
\'href\' => \'#\',
\'meta\' => array(
\'title\' => __(\'My Second Sub Menu Item\'),
\'target\' => \'_blank\',
\'class\' => \'my_menu_item_class\'
),
));
}
?>
我还添加了这个函数来运行else函数的样式。php但它不起作用:
function load_custom_wp_admin_style($hook) {
// Load only on ?page=mypluginname
if($hook != \'toplevel_page_mypluginname\') {
return;
}
wp_enqueue_style( \'custom_wp_admin_css\', plugins_url(\'admin-style.css\', __FILE__) );
}
add_action( \'admin_enqueue_scripts\', \'load_custom_wp_admin_style\' );