Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I remove "edit your profile" submenu under "my-account-with-avatar" admin menu bar, while still keeping the avatar and logout?

share|improve this question

3 Answers 3

up vote 8 down vote accepted

There is a remove_menu hook for the admin menu bar.

The class you want to hook into $wp_admin_bar , you can see the remove function here and test it out since there is no documentation on it ( line 86), it should work with the submenu ID.

http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/class-wp-admin-bar.php

Since you did not seem to believe me here is the code.........

function ya_do_it_admin_bar_remove() {
        global $wp_admin_bar;

        /* **edit-profile is the ID** */
        $wp_admin_bar->remove_menu('edit-profile');
 }

add_action('wp_before_admin_bar_render', 'ya_do_it_admin_bar_remove', 0);
share|improve this answer
    
There is no individual hook for "edit my profile". It's either I loose the whole account menu with logout and edit profile and avatar (if any), or keep them all. So, I ended up editing admin-bar.php –  Sean Lee Jul 17 '11 at 19:05
1  
The above code takes the ID's, the submenu item surely has an ID, do not hack core files, they are overwritten on updates besides about 100 other reasons. –  Wyck Jul 17 '11 at 19:39
    
Unfortunately there isn't any individual ID for edit my profile. BTW, this item is located in admin-bar.php. Unless you found something different that I missed. Please let me know. –  Sean Lee Jul 17 '11 at 23:20
    
I know what it is for and it has and ID, dump out the admin bar menu array and you will see it, you can also see it in the core file I linked above, $child = array( 'id' => $id, 'title' => $title, 'href' => $href ); –  Wyck Jul 18 '11 at 3:02
    
Added code to OP since you seem to not believe me....but thanks for the downvote... –  Wyck Jul 18 '11 at 3:29

I'm not sure if you can remove it (haven't checked), but you may achieve the same using css to hide the edit your profile link. The list item has an id 'wp-admin-bar-edit-profile' which you use to hide it. This is the html used in the admin bar:

<li id="wp-admin-bar-edit-profile" class="">
  <a href="http://www.example.com/wp-admin/profile.php">Edit My Profile</a>
</li>

I'm using the following css:

#wp-admin-bar-edit-profile { display: none }

This hides the link in the admin bar without any of the other links. Add this css snippet to your theme's style.css and the link will be hidden in the admin bar when viewing your site. Hiding it in the admin bar when viewing the WordPress backend involves a bit more and might be moot since there's also a link to the profile in the menu on the left.

share|improve this answer
    
Hiding it is not clean enough, HOw about rewrite, anyway to rewrite it? –  Sean Lee Jul 15 '11 at 17:49

Wordpress has introduced new stufs (nodes).

I was searching for remove completly the 'user account box' and add a simple logout :

//http://codex.wordpress.org/Function_Reference/get_nodes
//http://codex.wordpress.org/Function_Reference/add_node

add_action( 'admin_bar_menu', 'remove_my_account', 999 );
function remove_my_account( $wp_admin_bar ) {
    $wp_admin_bar->remove_node( 'my-account' );
}


add_action( 'admin_bar_menu', 'add_logout', 999 );
function add_logout( $wp_admin_bar ) {
    $args = array(
        'id'     => 'logout',           // id of the existing child node (New > Post)
        'title'  => 'Se déconnecter',   // alter the title of existing node
        'parent' => 'top-secondary',    // set parent
    );
    $wp_admin_bar->add_node( $args );
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.