TinyMCE default link target to “_blank”

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

Leave a Comment