Open link in a new tab checked by default when adding a new link in visual post editor

When adding a link in the WP visual post editor you have to click the settings after adding the link and then click the Open link in a new tab to have it add a link with a target in a new window/tab.

I am looking for a way to have this automatically checked by default. Is there a filter or JavaScript code to do this?

enter image description here

2 Answers
2

Add this function in your theme’s functions.php

function my_enqueue($hook) {
    if ('post.php' != $hook ) {
        return;
    }
    wp_enqueue_script('my_custom_script', get_template_directory_uri() . '/js/myscript.js');
}

add_action('admin_enqueue_scripts', 'my_enqueue');`

In myscript.js place this code

jQuery(document).ready(function(){
  jQuery('#wp-link-target').prop("checked", true);
})

It worked for me.

Leave a Comment