Add visit site to your toolbar instead of being in the dropdown

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.

Leave a Comment