Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Search Function in Admin Bar


Nick Watson
Participant

@nickbwatson

in your plugins folder (if you don’t already have one created) create a file called bp-custom.php

within that file put:

<?php

function new_search_action() {
global $bp;

return apply_filters( 'new_search_action', $bp->root_domain . '/search' );
}

function custom_adminbar_search() {
$mobSearch = '
<li class="align-right"><form action="' . new_search_action() . '" method="post" id="search-form">
<input type="text" id="search-terms" name="search-terms" value="" />
<input type="submit" name="search-submit" id="search-submit" value="" />

' . bp_search_form_type_select() . '

' . wp_nonce_field( 'bp_search_form' ) . '
</form></li>
';

echo apply_filters( 'bp_search_form', $mobSearch );
}
add_action('bp_adminbar_menus', 'custom_adminbar_search', 100);

?>

This will get your search to the top, and placed on top of your “visit” button. If you get rid of the class="align-right" in the list tag, then it’ll put it beside the notification button. You’ll notice that things seem a little screwy when you scale the page, so you’ll need to play around with putting a div around it etc etc. But at least this’ll get it up there for you.

To remove items from your admin bar:

function modify_adminbar(){
remove_action( 'bp_adminbar_logo', 'bp_adminbar_logo' );
remove_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
remove_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
remove_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
remove_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 );
remove_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 );
remove_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
}
add_action('plugins_loaded','modify_adminbar',99);

This removes ALL of the previous functions, so lets say you want to remove.. the visit button:

function modify_adminbar(){
remove_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
}
add_action('plugins_loaded','modify_adminbar',99);

And there you go. Hope that helped.

Skip to toolbar