Add menu items to the admin bar

This coding will add menu items to the top menu bar in the administration view. The code can be added to the theme's functions.php or used in a plugin. It's just for convenience.

top-admin-menu-bar.jpg

 

add_action('admin_bar_menu', function($admin_bar)
{
	$admin_bar->add_menu([
		'id'    => 'new-post',
		'title' => 'New Post',
		'parent'  => false
	]);
	$admin_bar->add_menu([
		'id'    => 'new-page',
		'title' => 'New Page',
		'parent'  => false
	]);
	$admin_bar->add_menu([
		'id'    => 'nav-menus',
		'title' => 'Menu',
		'href'  => 'nav-menus.php',
	]);
	$admin_bar->add_menu([
		'id'    => 'widgets-list',
		'title' => 'Widgets',
		'href'  => 'widgets.php',
	]);
	
	// if user has capability to do tasks
	if( current_user_can('manage_options') ) 
	{
		$admin_bar->add_menu([
			'parent' => 'new-content', // add to existing New parent
			'id' => 'new_plugin',
			'title' => 'Upload Plugin',
			'href' => admin_url('plugin-install.php?tab=upload')
		]);
		$admin_bar->add_menu([
			'parent' => 'new-content',
			'id' => 'new_theme',
			'title' => 'Upload Theme',
			'href' => admin_url('theme-install.php?upload')
		]);
	}
}, 999);

 




Copyright © 2021 CMSEnergizer.com. All Rights Reserved.
File download and article manager component by CMSE Custom Fields | Website hosting and development by WebsiteDons

CMSEnergizer.com is owned and operated by Emuzement Net Inc, Tampa, Florida USA