I’m looking for a way to move the “Visit Site” link from drop-down and add it to the main toolbar, just like in the image shown below:
2 s
Not complicated, but a little tricky to get timing right.
Something like this should work, but you might need to experiment with priority to get the link to specific position on the bar:
add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {
if ( ! is_admin() ) {
return;
}
/** @var WP_Admin_Bar $wp_admin_bar */
$wp_admin_bar->remove_node( 'view-site' );
$wp_admin_bar->add_menu( array(
'id' => 'view-site',
'title' => __( 'Visit Site' ),
'href' => home_url( "https://wordpress.stackexchange.com/" ),
) );
}, 31 ); // After `wp_admin_bar_site_menu()` at 30.