0

i added a menu to admin bar menu but it's style doesnt work;it looks like has default style

 <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'
            ),
        ));
    }

?>

i also added this function to run style from else function.php however it didnt work:

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' );
0

To override the default styles you have to use more specific selectors.

#wpadminbar .my_menu_item_class {
    background: yellow;
}  
#wpadminbar .menupop.hover ul li.my_menu_item_class > a {
    color:red;
}
  • it doesnt change the part of showing on toolbar when it change sub menu style.for example, sub-menu background color is yellow buut i dont see red color anywhere.also where i can find the selector list with comment lines? i looked at the csses in admin folder but i didnt find "wpadminbar" in lines. – Murat Deniz Jul 12 at 18:16
  • You are looking for wp-includes/css/admin-bar.css. – nmr Jul 12 at 18:26
  • ok thank you for your help – Murat Deniz Jul 12 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.