0

I would like to set the Open in New tab as default option. So that when I add a new URL in a text I would like to automatically tick the box to open the link in a new tab.

enter image description here

I am running on Version 5.1.1. I tried to create the following plugin:

    <?php
/*
Plugin Name: New Tab Always
Description: Ensure that the new tab is always clicked.
Plugin URI: 
Author: 
Author URI: 
Version: 0.1
License: 
*/

add_action( 'admin_head', function() {
    global $pagenow;
    if ( $pagenow === 'post.php' ) {
        ?>
        <script>
            jQuery(document).ready(function($){
                var linkTarget = jQuery( '#wp-link-target' );
                if ( linkTarget.length ) {
                    linkTarget.prop( 'checked', true );
                }
            });
        </script>
        <?php
    }
});

However, I still get the old behavior of not having the button clicked.

Any suggestions what I am doing wrong?

I appreciate your replies!

  • Are you able to add a target="_blank" to the anchor tags you're targeting? For example, <a href="#" target="_blank">text</a> – MikeNGarrett Mar 27 at 14:57
  • This is a React problem, you're probably not gonna solve it with jQuery. Maybe you could get this working by figuring out what event fires when that dialog box is opened and then hook your jQuery call onto that, but it would be super hacky. – mrben522 Mar 27 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.