Since 4.0, when you save a post as a Draft the View Post link opens the saved post in a new tab. (target ="_blank")

Is there a way to revert back to the previous behaviour (which was to open the Preview version in the -same- tab?

What's weird is that once the post is published, the saved version opens in the same tab (as in previous WP versions.)

I looked at this post (which seems to be the reverse) Make “Post published. View post” Open in a New Tab

I found that by editing line 93 from:

10 => sprintf( __('Post draft updated. <a href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),


10 => sprintf( __('Post draft updated. <a href="%s">Preview post</a>'), esc_url( add_query_arg( 'preview', 'false', $permalink ) ) ),

That does what I want. HOWEVER, that's hacking the core. Is there a way to modify this WITHOUT hacking this file?


1 Answer 1


You can hack by adding below lines in your theme's functions.php file.

function remove_preview_target()
    // below JS code will set Preview button's **target** attribute to **_self**, it means same tab/window.
    echo "<script>
        jQuery('#post-preview').attr('target', '_self');

// this action performs in admit footer
add_action('admin_footer', 'remove_preview_target');

Or add below lines in your JS file.

jQuery(document) . ready(function () {
     jQuery("#post-preview") . attr("target", "_self");
  • Thanks. I modified your answer slightly to indicate that one has to enqueue the JS in the admin separately from the 'regular' pages.
    – jchwebdev
    Jun 29, 2015 at 17:35

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.