I have managed to make the admin bar "Visit site" to open in a new window. But in a multisite setup there is a menu item called "My sites" which displays all your sites with a link to "Dashboard" and "Visit site". How do I make this "Visit site" button open in a new link?

Thank you!

EDIT: Here is the solution for the drop-down menu "My sites":

add_action( 'admin_bar_menu', 'remove_nodes_mysites', 999 );
function remove_nodes_mysites( $bar )
    $sites = get_blogs_of_user( get_current_user_id() );
    foreach ( $sites as $site )
             // Open Visit Site in new window/tab
             $visit_site_node = $bar->get_node( "blog-{$site->userblog_id}-v" ); // Visit Site
             $visit_site_node->meta['target'] = '_blank';
  • Maybe you could share exactly how you managed to do this on non-multisite setup, so others may give you answers starting from there to make it work with multisite. – Iceable May 22 '18 at 7:55
  • I think you misunderstood. Both are on the same multisite, it is just that there are two "Visit site", one in the top admin bar (which I have been able to solve), and one under the "My sites" menu. Check here: codex.wordpress.org/Dashboard_My_Sites_Screen – joq3 May 22 '18 at 8:17
  • I misunderstood this indeed. You could still share how you managed to solve this first part though, it can be useful as a starting point to answer your question. – Iceable May 22 '18 at 8:32
  • 1
    Just added that to my first post! – joq3 May 22 '18 at 9:28

This should do it (put it in a network activated plugin):

add_filter( 'myblogs_blog_actions', 'my_sites_visit_site_target_blank', 10, 2 );

function my_sites_visit_site_target_blank( $actions, $user_blog ) {
    $to_replace = ">" . __( 'Visit' ) . '</a>';
    $to_replace_with = " target='_blank' >" . __( 'Visit' ) . '</a>';
    return str_replace( $to_replace, $to_replace_with, $actions );
  • Sorry, this doesn't work. I think what this does is what I posted in my first post. It opens the Visit site (in the admin top bar drop down). What I am looking for is the "Visit" button/link inside the menu "My sites", check here: codex.wordpress.org/Dashboard_My_Sites_Screen – joq3 May 22 '18 at 9:31
  • @joq3 Ah, sorry, I misunderstood. Now I changed my answer. – Nikolay May 22 '18 at 9:54
  • 1
    Fantastic! Really appreciate it! – joq3 May 22 '18 at 10:17
  • @joq3 Cool, no problem :) – Nikolay May 22 '18 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.