$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugin development - How to add HTMLForm to an Admin Bar Menu|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin development - How to add HTMLForm to an Admin Bar Menu

matteradmin7PV0评论

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.

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.

Share Improve this question asked Jun 25, 2012 at 19:53 GStoGSto 4232 gold badges8 silver badges15 bronze badges 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
Add a comment  | 

2 Answers 2

Reset to default 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.

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' );
Post a comment

comment list (0)

  1. No comments so far