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.

How can I add a sub menu link using add_submenu_page that will open a new window (target="_blank") instead of opening in the current one (default behavior)?

share|improve this question
    
A good question :) Any help on this? –  diosney Sep 23 '12 at 20:35
add comment

1 Answer

up vote 1 down vote accepted

This has to be solved:

  • with an unconventional submenu manipulation, provided by @t31os in this Answer
  • and some jQuery
add_action( 'admin_menu', 'wpse_66020_admin_menu_new_item' );
add_action( 'admin_head', 'wpse_66020_add_jquery' );

function wpse_66020_admin_menu_new_item() 
{
    global $submenu;
    $submenu['index.php'][500] = array( 
                                    '<div id="wpse-66020">Go to WPSE</div>'
                                ,   'manage_options' 
                                ,   'http://wordpress.stackexchange.com/' 
                                ); 
}

function wpse_66020_add_jquery() 
{
    ?>
    <script type="text/javascript">
        jQuery(document).ready( function($) {   
            $('#wpse-66020').parent().attr('target','_blank');  
        });
    </script>
    <?php
}

Resulting in this:

submenu with _blank target
click to enlarge

share|improve this answer
    
thanks, I will check and let you know –  gsc-leticia Nov 17 '12 at 14:12
add comment

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.