WordPress at Your Fingertips

How to Add Dashicon to Admin Bar Menu Item Title

For doing this you need additional to dashicons class add ab-icon class to HTML element specified in title attribute. Let's look at such example:

add_action( 'admin_bar_menu', 'add_toolbar_link', 70 );

function add_toolbar_link( $wp_admin_bar ){

	$wp_admin_bar->add_menu( [
		'id'    => 'chartlink',
		'title' => '<span class="ab-icon dashicons-visibility"></span><span class="ab-label">Views</span>',
		'href'  => '#',
	] );
}

As a result, we will get:

No comments
    Log In