Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to disable the admin bar search field when certain users, belonging to specific roles are logged in. I would like to keep the search field available for the role 'admin', but not others.

This post tells me how to remove the admin bar completely, but doesn't give any info regarding how to selectively remove elements of it.

Does anyone have experience with this?

Thanks, jml

share|improve this question
What have you tried so far? – kaiser Jan 20 '14 at 21:57
@kaiser - I don't know where to start. Anything helps. I was able to disable the search field for the front-facing site via style.css and header.php in my child theme, but that is only for the outside. – jml Jan 20 '14 at 22:04
Maybe start by showing us that you're able to run any code in the admin UI or what your search for the admin toolbar and the search field returned. – kaiser Jan 20 '14 at 22:08
Uhm... I searched this site and the WP support site, to no avail. I haven't found any information on doing this. It could be that it's a yes or no question to "is it possible", but I have no experience with it. Here's the only stackexchange query that is even remotely related:… ...Also, not sure what you mean by "show us that you're able to run any code in the admin UI" - that seems to be a bit off topic. – jml Jan 21 '14 at 0:55
Please file edits for additional info (instead of comments). For your reasearch: Try "adminbar". – kaiser Jan 21 '14 at 1:25

1 Answer 1

Just in case anyone trips over's how you remove "search" and some examples of other things you can remove from the admin bar:

public function remove_admin_menu_bar_items ($wp_toolbar) {
    $wp_toolbar->remove_node( 'my-sites' );
    $wp_toolbar->remove_node( 'wp-logo' );
    $wp_toolbar->remove_node( 'new-content' );
    $wp_toolbar->remove_node( 'view' );
    $wp_toolbar->remove_node( 'search' );  // remove the search element
    return $wp_toolbar;
add_filter( 'admin_bar_menu', 'remove_admin_menu_bar_items' );

Codex reference:

And to completely answer the question, you can execute this code (using conditional logic), based on first querying the current user if you want to test for a specific role/capability:

$current_user = wp_get_current_user();

$current_user will be an object and one of the properties is the role(s) the user has.

Codex reference:

share|improve this answer
This answer not address the question which is how to remove the search for specific users/roles. – s_ha_dum Nov 23 at 3:06
ok, I added that... – C C Nov 23 at 3:24

Your Answer


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.