# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Admin](https://wpide.com/library/category/admin/)
- Tags: admin, admin-bar, links
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/visit-site-new-tab/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Open "Visit Site" in a New Tab" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
