Skip to content

Gambit

We strategize & create powerful websites for businesses & tools for developers

  • Home
  • Work
  • Blog
  • Support
  • Contact Us

Tag: admin bar

WordPress

WordPress: How to Add a Button in the Admin Bar

This snippet will add a button on the admin bar:

add_action( 'admin_bar_menu', array( $this, 'addToggleButton' ), 99 );
public function addToggleButton( $adminBar ) {
    $args = array(
        'id' => 'my_button',
        'title' => 'My Button',
        'href' => '#',
        'meta' => array(
            'class' => 'my_class',
            'onclick' => 'alert("I was clicked")',
        ),
    );
    $adminBar->add_node( $args );
}
July 4, 2015admin, admin bar, button, wordpressLeave a comment
Theme by Stackable.