Removing Items From the Admin Bar
-
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.
-
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.
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).
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).
- The topic ‘Removing Items From the Admin Bar’ is closed to new replies.