3

I am struggling to change the default_link_target to "_blank". Here is what i have in functions.php:

function my_format_TinyMCE( $settings ) {

    $settings['default_link_target'] = "_blank";
    return $settings;

}
add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE', 1000 );

This does not give any result, althought the overall approach is correct, as changing another setting works, for example when modifying the default height :

function my_format_TinyMCE( $settings ) {
    $settings['height'] = 800;
    return $settings;
}
add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE', 1000 );

Any ideas ?

Cheerz...

Johan

2
  • 1
    WordPress 4.5 introduced the inline link editor, so perhaps the tinyMCE settings are no longer effective for changing the link behavior. Browsing through the tinyMCE related PHP and JS, I didn't see any kind of filter or option to allow this and found this post on Make WordPress Core where the whole idea was poo-pood on pretty hard. It's still likely possible to do, but I presume it would require some JS being loaded with tinyMCE that handles the #wp-link-target checkbox. Commented Sep 22, 2016 at 21:39
  • sure! Add custom options to the wplink dialog has some great insights on taking this further. Commented Sep 22, 2016 at 22:25

1 Answer 1

1

I was able to achieve this by replacing the wplink plugin with tinyMCE's default link plugin, and then using the original function as is.

I created my own plugin though for the whole tinyMCE editor, and then copy/pasted the individual plugin folders from wp-includes/js/tinymce/plugins, and then only included the 'link' plugin, so what I wound up with was like this:

function tiny_bbp_visual_editor_buttons( $buttons = array() ) {
        $buttons['tinymce'] = array(

        // Add the link button in the toolbar
            'toolbar1' => 'link'
        );

        return $buttons;
    }


function my_format_TinyMCE( $settings ) {

        // Set the target to blank

        $settings['default_link_target'] = "_blank";
        return $settings;
    }

function tiny_bbp_visual_editor_plugins( $plugin_array ) {

        // Add the link plugin

        $plugin_array['link']       = plugins_url( '/mce/link/plugin.min.js', __FILE__ );

        return $plugin_array;
    }

Note: I used this for bbPress, and so I used specific bbPress filters for parts of it. But for the standard editor, I'd think you can leave out the first two filters:

add_filter( 'bbp_after_get_the_content_parse_args', 'tiny_bbp_enable_visual_editor' );

add_filter( 'bbp_after_get_the_content_parse_args',  'tiny_bbp_visual_editor_buttons' );

add_filter( 'mce_buttons', 'tiny_bbp_visual_editor_buttons' );

add_filter( 'mce_external_plugins', 'tiny_bbp_visual_editor_plugins' );

add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE', 1000 );

(It should go without saying, but this code will give you a TinyMCE editor that only includes a "Link" button...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.