Make Visit Site links open in a new window in admin bar

Shortlink:

Make Visit Site links open in a new window

This is the “Visit Site” link found under: My Sites Menu > Site Name > Visit Site

/*
* Make Visit Site links open in a new window: My Sites > Site Name > Visit Site
*/
function my_site_links() {
global $wp_admin_bar;
foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
$menu_id = 'blog-' . $blog->userblog_id;
$wp_admin_bar->add_menu( array(
'parent' => $menu_id,
'id' => $menu_id . '-v',
'title' => __( 'Visit Site' ),
'href' => get_home_url( $blog->userblog_id, '/' ),
'meta' => array( target => '_blank' ) )
);
}
}
add_action( 'wp_before_admin_bar_render', 'my_site_links' );

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!