• How To?
  • Tips ‘n Tricks
  • WordPress
  • Snippets
  • Software
    • Browsers
    • Downloads
  • Web
  • Tools
    • Character Counter
    • chmod Calculator
    • Entities Encoder
    • Live HTML Editor
    • My IP
  • Contact
Twitter Facebook Google+ RSS
You are here: SumTips » Blogging » Customize WordPress Admin Bar by Adding/Removing Links

Customize WordPress Admin Bar by Adding/Removing Links

Posted on March 1, 2011 by Renji | Short URL: http://sumtips.com/?p=3602

You might have already updated to the latest WordPress 3.1. This version comes with a handy admin bar that provides signed-in users quick access to some Admin features, directly from the main site.

WordPress has not provided any options to customize this bar, that is, you cannot add or remove any links. But there are still ways to do so by creating functions. Here I will show, how you can customize the Admin bar the way you want.

Add Single Links on the Admin Bar

Custom Link on Admin Bar

Custom Link on Admin Bar

To add a new custom link on the WordPress admin bar, drop the following function in your theme’s functions.phpfile.

function add_sumtips_admin_bar_link() {
	global $wp_admin_bar;
	if ( !is_super_admin() || !is_admin_bar_showing() )
		return;
	$wp_admin_bar->add_menu( array(
	'id' => 'sumtips_link',
	'title' => __( 'SumTips Menu'),
	'href' => __('http://sumtips.com'),
	) );
}
add_action('admin_bar_menu', 'add_sumtips_admin_bar_link',25);

Change the id, title and href value with your own.

Create Link Submenus on the Admin Bar

Submenu Links

Now here, we will first create two sub-items (“View All Posts” and “Downloads”) for the link “SumTips Menu.” Then again, add another new link (“Browsers”) as a child item to the “Downloads” menu.  This will create a two-level menu on the Admin bar.

function add_sumtips_admin_bar_link() {
	global $wp_admin_bar;
	if ( !is_super_admin() || !is_admin_bar_showing() )
		return;
	$wp_admin_bar->add_menu( array(
	'id' => 'sumtips_link',
	'title' => __( 'SumTips Menu'),
	'href' => __('http://sumtips.com'),
	));

	// Add sub menu link "View All Posts"
	$wp_admin_bar->add_menu( array(
		'parent' => 'sumtips_link',
		'id'     => 'sumtips_all',
		'title' => __( 'View All Posts'),
		'href' => __('http://sumtips.com/all'),
	));

	// Add sub menu link "Downloads"
	$wp_admin_bar->add_menu( array(
		'parent' => 'sumtips_link',
		'id'     => 'sumtips_downloads',
		'title' => __( 'Downloads'),
		'href' => __('http://sumtips.com/downloads'),
		'meta'   => array(
			'class' => 'st_menu_download',),
	));
		$wp_admin_bar->add_menu( array(
			'parent' => 'sumtips_downloads',
			'id'     => 'sumtips_browsers',
			'title' => __( 'Browsers'),
			'href' => __('http://sumtips.com/downloads?category=3'),
		));
}
add_action('admin_bar_menu', 'add_sumtips_admin_bar_link',25);

You can add more links and submenus by extending this single function as per your needs.

We can also pass parameters to the link items, useful for applying CSS. An example of this can be seen above for “Downloads” link.

Remove Links from the Admin Bar

You can easily remove any and all links that are found by default on the Admin bar. In this example, I have removed the WordPress logo and Updates link.

Remove link from WordPress Admin Bar
function remove_admin_bar_links() {
	global $wp_admin_bar;
	$wp_admin_bar->remove_menu('wp-logo');
	$wp_admin_bar->remove_menu('updates');
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );

IDs for other top links:

  • wp-logo: WordPress logo
  • my-account: Links to your account. The ID depends upon if you have avatar enabled or not.
  • site-name: Site name with other dashboard items
  • my-sites : My Sites menu, if you have more than one site
  • get-shortlink : Shortlink to a page/post
  • edit : Post/Page/Category/Tag edit link
  • new-content : Add New menu
  • comments : Comments link
  • updates : Updates link
  • search: Search box

Get Delete Link on ‘Posts’ and ‘Page’ Pages

Delete link on WordPress Admin Bar

With the following code snippet, you can add a quick-delete button on all posts and pages. Button stays hidden on all other pages of your site.

function admin_bar_delete_option() {
  global $wp_admin_bar;
  if ( !is_super_admin() || !is_admin_bar_showing() )
      return;
  $current_object = get_queried_object();
  if ( !empty( $current_object->post_type ) &&
     ( $post_type_object = get_post_type_object( $current_object->post_type ) ) &&
     current_user_can( $post_type_object->cap->edit_post, $current_object->ID )
  ) {
    $wp_admin_bar->add_menu(
        array( 'id' => 'delete',
            'title' => __('Delete'),
            'href' => get_delete_post_link($current_object->term_id)
        )
    );
  }
}
add_action( 'admin_bar_menu', 'admin_bar_delete_option', 40 );

Move Admin Bar to the Bottom of Page

Admin Bar at the Bottom of Page
function move_admin_bar() {
    echo '<style type="text/css">
	body {
		margin-top: -28px;
		padding-bottom: 28px;
	}
	body.admin-bar #wphead {
		padding-top: 0;
	}
	body.admin-bar #footer {
		padding-bottom: 28px;
	}
	#wpadminbar {
		top: auto !important;
		bottom: 0;
	}
	#wpadminbar .quicklinks .menupop ul {
		bottom: 28px;
	}
	</style>';
}
add_action( 'admin_head', 'move_admin_bar' );
add_action( 'wp_head', 'move_admin_bar' );

That’s all. :)


Tweet

Related posts:

  • 10 Plugins and Themes to Customize WordPress Admin Dashboard
  • Hide WordPress Update Nag in Admin Dashboard
  • WordPress 3.1 Final Released
  • Customize WordPress TinyMCE Editor With Custom Buttons
  • Find Full Download Links of Online Installers and Streaming Multimedia
Categories: Blogging, How To? | Tags: Tips 'n Tricks, WordPress
Encrypt a USB Flash Drive using TrueCrypt on Ubuntu
Set Different Favicons for Frontend, Backend and Login Page on WordPress

122 Responses to “Customize WordPress Admin Bar by Adding/Removing Links”

  1. Blackbox Debug Bar Plugin, Now WP Toolbar Compatible! | Archonic says:
    June 10, 2012 at 4:10 AM

    [...] Blackbox Debug Bar UpdateWhile you’re at it, you may want to take some time to customize the WP toolbar. No one needs that pesky logo in the upper left and the admin bar is especially useful for [...]

  2. custom wordpress theme design says:
    July 26, 2012 at 2:50 AM

    I ended up this blog a few weeks back and I seriously can’t get enough! Please keep writing!

  3. custom wordpress development says:
    July 26, 2012 at 3:34 AM

    Admiring the persistence you put into your website and in depth information you
    present. It’s nice to come across a blog every once in a while that isn’t the same old rehashed information.
    Great read! I’ve saved your site and I’m adding your RSS feeds to my
    Google account.

  4. advertising companies in boston says:
    July 26, 2012 at 8:33 AM

    Thank you for this great article. This was just what I needed to see :)

  5. website analysis says:
    July 29, 2012 at 9:14 AM

    Hey there, I think your site might be having browser compatibility
    issues. When I look at your website in Firefox,
    it looks fine but when opening in Internet Explorer, it has
    some overlapping. I just wanted to give you a quick heads up!
    Other then that, superb blog!

  6. Yogurt Website Design says:
    August 2, 2012 at 5:26 AM

    Tried, but this code doesn’t work on Multisite or the latest version of WordPress.

« Previous 1 2 3 4
  • Get Updates via Email

  • Recent Posts

    • CMS2CMS: Migrate Site from Drupal or Joomla to WordPress
    • WordPress: Add Preview Button in Distraction Free Writing
    • How to Activate or Deactivate Individual Jetpack Modules
    • Windows 8: Auto Update Defender with Windows Update Disabled
    • Automatically Start and Close Programs at Specific Time
    • How to Copy Code from Notepad++ with Syntax Highlighting
  • Random Posts

    • Strip Metadata off Images
    • Set a Doodle as Your Permanent Google Icon
    • Search and Replace Clipboard Text with AutoHotkey
    • WordPress App for Windows Phone 7 Released
    • Add Thumbnail Support for 162 Image formats in Explorer with SageThumbs
    • Encrypt a USB Flash Drive using TrueCrypt on Ubuntu
  • Categories

    • Blogging
    • Games
    • Google
    • How To?
    • Linux
    • Microsoft
      • Windows
    • Miscellaneous
    • Phone
    • Snippets
      • AutoHotkey Snippets
      • CSS Snippets
      • htaccess Snippets
      • JavaScript Snippets
      • PowerShell Snippets
      • WordPress Snippets
    • Social
    • Software
      • Browsers
    • Tips 'n Tricks
    • Wallpapers
    • Web
© SumTips. Contact | Sitemap | Privacy Policy