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 );
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*