Created
January 14, 2014 01:02
-
-
Save simongcc/8411127 to your computer and use it in GitHub Desktop.
Customize admin bar in Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
top admin toolbar aka admin bar | |
remove unnecessary admin toolbar items | |
Version Tested: 3.6, 3.8 | |
Reference: | |
http://wordpress.stackexchange.com/questions/47824/modify-admin-bar-link | |
*/ | |
function custom_admin_bar_link() { | |
global $wp_admin_bar; | |
//Get a reference to the new-content node to modify. | |
$new_content_node = $wp_admin_bar->get_node('new-content'); | |
// Parent Properties for new-content node: | |
//$new_content_node->id // 'new-content' | |
//$new_content_node->title // '<span class="ab-icon"></span><span class="ab-label">New</span>' | |
//$new_content_node->parent // false | |
//$new_content_node->href // 'http://www.somedomain.com/wp-admin/post-new.php' | |
//$new_content_node->group // false | |
//$new_content_node->meta['title'] // 'Add New' | |
//Change href | |
$new_content_node->href = 'edit.php?post_type=wo_shop'; | |
//Update Node. | |
$wp_admin_bar->add_node($new_content_node); | |
//Customize existing menu item in + New. | |
$wp_admin_bar->remove_menu('new-post'); //new post link | |
$wp_admin_bar->remove_menu('comments'); //new comments | |
//further control between admin and other users | |
if ( !is_super_admin() || !is_admin_bar_showing() ) | |
{ | |
$wp_admin_bar->remove_menu('new-page'); //new post page | |
} | |
//Customize an existing menu item in about. | |
$wp_admin_bar->remove_menu('wp-logo-external'); //external link: documents, support forums, wordpress, feedback | |
//a simple and clean way | |
$args = array( | |
'id' => 'wp-logo', | |
'href' => 'http://www.example.com', | |
'meta' => array( 'title' => 'About example' ) | |
); | |
$wp_admin_bar->add_node( $args ); //add if non exist or update existing object | |
//alternative way to write the code | |
$about_node = $wp_admin_bar->get_node('about'); | |
$about_node->href = 'http://www.example.com'; | |
$about_node->title = 'About example'; //display name, not the title in tag | |
$about_node->meta = array( 'title' => 'About example' ); //html, class... | |
$wp_admin_bar->add_node($about_node); | |
} | |
add_action( 'wp_before_admin_bar_render', 'custom_admin_bar_link' ); //if place in admin_bar_menu hook, too late to hide for some elements |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment