0

I am using this code to open the admin "Visit Site" URL in a new window. How could I modify the code to also point the URL to a custom page? e.g. www.domain.com/blog

add_action( 'admin_bar_menu', 'customize_my_wp_admin_bar', 80 );
function customize_my_wp_admin_bar( $wp_admin_bar ) {

    //Get a reference to the view-site node to modify.
    $node = $wp_admin_bar->get_node('view-site');

    //Change target
    $node->meta['target'] = '_blank';

    //Update Node.
    $wp_admin_bar->add_node($node);

}
1

The admin bar is using the home_url() function which you can modify the result by using the "home_url" filter, this will change a lot of links on your admin area so looks like it's not the best solution, anyway remember to use the is_admin() conditional tag or you will affect everything on the front end too.

https://github.com/WordPress/WordPress/blob/master/wp-includes/admin-bar.php#L357

The second option is to set the href directly:

    $node->href = 'https://www.google.com';

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.