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

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:

enter image description here

2 s
2

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