David Stockdale's Scrapcode

Adding and removing Links on wpAdminBar

If you are like me you have a lot of plugins clogging up your admin bar with unnecessary links.

You might also have some important parts of your site you would like to be more readily accessible (such as private posts that serve as guides for your users or admin pages hidden behind several menus).

The solution to both of these problems is the ability to add and remove links from the admin bar.

Adding Links To Admin Bar

This can be done by adding to your “functions.php” this simple bit of code:

 * Adds a link to the WP Admin Bar.
function wpb_custom_toolbar_link($wp_admin_bar) {
    $args = array(
        'id' => 'guide',
        'title' => 'Guide', 
        'href' => 'YOUR LINK HERE', 
        'meta' => array(
            'class' => 'guide', 
            'title' => 'Guide'
add_action('admin_bar_menu', 'wpb_custom_toolbar_link', 999);

Removing Links From Admin Bar

While existing links from plugins and WordPress itself can be removed with something like this:

 * Removes links from the WP Admin Bar.
function remove_admin_bar_links() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('updates');          // Remove the Updates
    $wp_admin_bar->remove_menu('comments');            // Remove the Comments
	$wp_admin_bar->remove_menu('wpforms-menu');            // Remove the  WPForms
	$wp_admin_bar->remove_menu('stats');            // Remove the Jetpack Stats
	$wp_admin_bar->remove_menu('wp-logo');            // Remove the WordPress Logo
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );

Leave a Reply