• Hello,

    I have way too many items on my Admin Bar, that overlap onto the site.

    So I’ve tried adding this to functions.php file (GeneratePress child theme) :

    function remove_toolbar_items($wp_adminbar) {
      	$wp_adminbar->remove_node('wp-admin-bar-updates');
      	$wp_adminbar->remove_node('wp-admin-bar-comments');
    	$wp_adminbar->remove_node('wp-admin-bar-stats');
      	$wp_adminbar->remove_node('wp-admin-bar-cs-explain');
    }
    add_action('admin_bar_menu', 'remove_toolbar_items', 999);

    But it did not change anything,

    Any idea of what might have cause the problem?

    Thanks in advance,

    v

    • This topic was modified 5 years, 2 months ago by eoik.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter eoik

    (@eoik)

    I installed this plugin : https://github.com/yingles/remove-from-admin-bar

    and it worked better.

    for all items except the stats and the sidebars…. so it only worked for the core items.

    • This reply was modified 5 years, 2 months ago by eoik.
    • This reply was modified 5 years, 2 months ago by eoik.
    Thread Starter eoik

    (@eoik)

    Ok, i compared the plugin scrpt and mine :

    instead of writing

    function remove_toolbar_items($wp_adminbar) {
      	$wp_adminbar->remove_node('wp-admin-bar-updates');
      	$wp_adminbar->remove_node('wp-admin-bar-comments');
    	$wp_adminbar->remove_node('wp-admin-bar-stats');
      	$wp_adminbar->remove_node('wp-admin-bar-cs-explain');
    }

    one should write :

    function remove_toolbar_items($wp_adminbar) {
      	$wp_adminbar->remove_node('updates');
      	$wp_adminbar->remove_node('comments');
    	$wp_adminbar->remove_node('stats');
      	$wp_adminbar->remove_node('cs-explain');
    }

    So remove the “wp-admin-bar-” from the id, and it’s fine. (even if not working for the latest plugin).

    Moderator bcworkz

    (@bcworkz)

    Despite hooking with 999 priority, you cannot remove items added from script hooked even later than that. Some coders go nuts with priority in an effort to be the last. Try a priority of PHP_INT_MAX and name your callback zzz_remove_toolbar_items(). For the same priority, functions are reportedly called alphabetically (unverified).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Removing Items From the Admin Bar’ is closed to new replies.