This code shows you how to use the remove_node
function with the admin_bar_menu
hook to remove unwanted admin bar link in WordPress.
add_action('admin_bar_menu', 'remove_monsterinsights_admin_bar_item', 999); function remove_monsterinsights_admin_bar_item($wp_admin_bar) { $wp_admin_bar->remove_node('monsterinsights_frontend_button'); }
Add the PHP code to the end of your child themes functions file.
How To Find The ID
We search the plugin folder for admin_bar_menu and we find this function :
function monsterinsights_add_admin_bar_menu() { if ( monsterinsights_prevent_loading_frontend_reports() ) { return; } global $wp_admin_bar; $args = array( 'id' => 'monsterinsights_frontend_button', 'title' => ' Insights', // Maybe allow translation? 'href' => '#', ); if ( method_exists( $wp_admin_bar, 'add_menu' ) ) { $wp_admin_bar->add_menu( $args ); } }
This gives us an array which includes the id which is monsterinsights_frontend_button
.
We add that to the remove_node() function and we get :
$wp_admin_bar->remove_node('monsterinsights_frontend_button');
which we hook to the admin_bar_menu
action hook.
Was This Tutorial Helpful?