Lightweight, practical WordPress plugins and experiments.
By default, WordPress opens the “Visit Site” link in the admin bar in the same browser tab. This replaces the current admin page and disrupts workflow when moving between the dashboard and the frontend.
This Lab provides a small, deterministic snippet that forces all frontend “Visit Site” admin bar links to open in a new browser tab, including multisite My Sites menu entries.
<?php
/**
* Force all "Visit Site" admin bar links to open in a new tab,
* including Multisite "My Sites" menu entries.
*/
add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {
$nodes = $wp_admin_bar->get_nodes();
if ( empty( $nodes ) ) {
return;
}
foreach ( $nodes as $node ) {
if ( empty( $node->href ) ) {
continue;
}
// Skip admin URLs; only affect frontend site links.
if ( strpos( $node->href, admin_url() ) === 0 ) {
continue;
}
// Leave nodes that already define a target.
if ( ! empty( $node->meta['target'] ) ) {
continue;
}
$wp_admin_bar->add_node( [
'id' => $node->id,
'title' => $node->title,
'href' => $node->href,
'parent' => $node->parent,
'meta' => array_merge(
$node->meta ?? [],
[
'target' => '_blank',
'rel' => 'noopener noreferrer',
]
),
] );
}
}, 100 );
This Lab is provided as a standalone snippet. It may later be folded into a plugin or remain a documented patch.