The WordPress editor allow authors to easily choose when a hyperlink opens the link in a new window or tab. It does this via a simple check box. You’ll see that this check box adds the target="_blank" attribute to the anchor element.

Insert/edit link

We are not a fan of opening a new window on a hyperlink, even external ones. Readers expect that websites won’t spawn new windows, nor do they appreciate that this breaks the back/forward button navigation in browsers. We also think it is a poor method of trying to “keep someone on your page.” There are plenty of strong opinions out there, but suffice it to say, we think it is simply too easy for authors to enable this on their posts in WordPress.

Given how often our writers were checking this box, we decided to simply hide it. Here is a simple snippet of javascript for your functions.php file so that you can do the same thing. It does two things. First, it makes sure that the checkbox for “open link in a new window/tab” is unchecked. Then it hides it via CSS. This gets loaded on the after_wp_tiny_mce hook.

//disable open in a new tab/window checkbox in TinyMCE
function disable_open_new_window() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            $('input#link-target-checkbox').prop('checked', false);
            $('#wp-link .link-target').css('visibility', 'hidden');
        });
    </script>
    <?php
}
add_action ('after_wp_tiny_mce', 'disable_open_new_window');

Latest Developer Blog Articles

Job Listings on GeekWork

Find more jobs on GeekWork. Employers, post a job here.