2

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

  • A good question :) Any help on this? – diosney Sep 23 '12 at 20:35
1

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' 
                                ,   'https://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

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.