Use This Snippet to Add Links to Admin Toolbar
Add the following code to your WordPress theme’s function.php file, or a functionality plugin. Modify the example for your link.
- diww where diww is the ID of your menu item.
- my-blogs where my-blogs is the parent ID of your menu item.
- Title of the link you want to add where Title of the link you want to add is the title you want to use for your menu item.
- http://mysitesurl.com/wp-admin.php where http://mysitesurl.com/wp-admin.php is the admin url of your menu item.
/** Use This Snippet to Add Links to Admin Toolbar */
function my_admin_bar_link() {
global $wp_admin_bar;
if ( !is_super_admin() || !is_admin_bar_showing() )
return;
$wp_admin_bar->add_menu( array(
'id' => 'diww',
'parent' => 'my-blogs',
'title' => __( 'Title of the link you want to add'),
'href' => admin_url( 'http://mysitesurl.com/wp-admin.php' )
) );
}
add_action('admin_bar_menu', 'my_admin_bar_link');
Use This Snippet to Remove Links to Admin Toolbar
Add the following code to your WordPress theme’s function.php file, or a functionality plugin.
- my-blogs where my-blogs is the ID of the menu item you want to remove
- my-account-with-avatar where my-account-with-avatar is the ID of the menu item you want to remove
/** Use This Snippet to Remove Links to Admin Toolbar */
function remove_admin_bar_links() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('my-blogs');
$wp_admin_bar->remove_menu('my-account-with-avatar');
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
Share Your Two Cents