Open "Visit Site" in a New Tab
Makes the site name and "Visit Site" links in the admin bar open the front end in a new tab, so you keep your place in the admin.
Opens WPIDE on
Code
add_action( 'admin_bar_menu', function ( $wp_admin_bar ) {
if ( ! is_admin() ) {
return;
}
foreach ( array( 'site-name', 'view-site' ) as $node_id ) {
$node = $wp_admin_bar->get_node( $node_id );
if ( ! $node ) {
continue;
}
$meta = (array) $node->meta;
$meta['target'] = '_blank';
$meta['rel'] = 'noopener';
$wp_admin_bar->add_node( array( 'id' => $node_id, 'meta' => $meta ) );
}
}, 999 );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.