Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to create a filter to make in sort that the link in the admin bar to open in a new window. I know that the right-click -> open in a new tab is a common use for us programmers but for the client who use it, it could be great to open in a new tab.

enter image description here

Hope to find a solution without changing the core file "admin-bar.php" so it won't get overwrite on any WP's updates.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

This is actually easily done. I just adapted the code from this answer

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);

}

To change any other item in the menu bar you just need to find the id of the item to change and adapt get_node. Look in /wp-includes/admin-bar.php for the id or have a look at the css classes of the output.

share|improve this answer
    
Nice it works. Just like that, is it possible to add this action on the parent. The one with the little house icon ? –  Warface Jun 6 at 14:40
1  
Have a look at the edited answer. You are looking for id site-name in wp-includes/admin-bar.php:285 –  kraftner Jun 6 at 14:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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