1

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

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.

  • Thanks I was thinking this might be the only way to do it as I found the WordPress file after posting this that creates that form and saw that it does not fire any hook or filters. Thanks – JasonDavis Jun 25 '16 at 17:14

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.