4

I'd like to add a custom form to the admin bar in Wordpress. is there a way to accomplish this? So far all of the documentation seems to only allow the addition of simple text links.

1
  • This plugin does it, if you happen to get the core of this functionality, please post it here ;o)
    – brasofilo
    Commented Jun 25, 2012 at 20:00

2 Answers 2

7

I just gave this a shot and it seemed to work fine:

function wpse_form_in_admin_bar() {
    global $wp_admin_bar;

    $wp_admin_bar->add_menu( array(
        'id' => 'wpse-form-in-admin-bar',
        'parent' => 'top-secondary',
        'title' => '<form><input type="text" /><input type="submit" /> </form>'
    ) );
}
add_action( 'admin_bar_menu', 'wpse_form_in_admin_bar' );

You'll have to do some work to gussy it up a bit, but it looks like there is a chance you can do what you want.

4

what @tollmanz suggested will probably work, but to avoid having your text breaking out the menu width, I would suggest

 function wpse_form_in_admin_bar() {
    global $wp_admin_bar;

    $wp_admin_bar->add_menu( array(
        'id' => 'wpse-form-in-admin-bar',
        'parent' => 'top-secondary',
        'title' => 'title_goes_here',
'meta'   => array(
            'target'   => '_self',
            'html'     => '<!-- Custom HTML that goes below the item --><form><input type="text" /><input type="submit" /> </form>',
        ),

) 

);
}
add_action( 'admin_bar_menu', 'wpse_form_in_admin_bar' );
1
  • I think this is much better! The @tollmanz answer is messy a bit! html tags inside an attribute?!!
    – kodfire
    Commented Jul 6, 2022 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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