Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6886303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:44:32+00:00 2026-05-27T05:44:32+00:00

I asked How can I make the Preview Post button save and preview in

  • 0

I asked How can I make the “Preview Post” button save and preview in the same window? on the WordPress Stack Exchange, but this may be a better question for Stack Overflow as it is more directly related to coding.

WordPress has a box that allows you to save, preview, and publish your blog posting:

Picture.png

The "Preview" button is actually a link styled as a button:

<a tabindex="4" id="post-preview" target="wp-preview"
href="/?p=67&amp;preview=true" class="preview button">Preview</a>

My problem is that I can’t seem to figure out how to get that link to open in the current window. Notice the target="wp-preview" part. I’m trying to get rid of that part, but I think there may be another function bound to that element because I really can’t get it to open in current tab / window, even after unbinding it and removing the target attribute.

I’m running the following code as part of a plugin (you can see more info on how to run this as a plugin below), but it is also possible to copy and paste this into Chrome or Firefox’s console to test this out yourself without even modifying WordPress. Please note that when testing you’ll need to use jQuery instead of $ in your own functions as WordPress uses the noconflict method, however the code below is working fine as is.

//select the node and cache the selection into a variable
var $node = jQuery('a.preview'); 

//add a 1px dotted outline to show we have the right element
$node.css('outline','1px dotted red'); 

//show current target
console.log($node.prop('target')); 
//show if anything is bound - nothing is for me ('undefined')
console.log($node.data('events')); 

//remove anything bound to it
$node.unbind(); 
//set target to _self (current window), just in case
$node.prop('target','_self'); 
//the remove the target attribute all together
$node.removeAttr('target'); 

//clone the node
var $clone = $node.clone(); 
//change the text to new
$clone.text('new'); 
//remove target from clone
$clone.removeAttr('target'); 
//unbind the clone
$clone.unbind(); 
//insert the clone after the original node
$node.after($clone); 

//show current target - now shows undefined for me
console.log($node.prop('target'));
//show if anything is bound - still 'undefined'
console.log($node.data('events'));

This is how you would work the code into a theme or plugin:

// set up an action to set a function to run in the wp admin_footer
add_action('admin_footer','my_admin_footer_script',9999);

Here is the function that adds the javascript:

//this function can then be used to add javascript code to the footer

function my_admin_footer_script(){ ?>
    <script type="text/javascript">
    jQuery(function($){
     (above js code here)
    });
    </script>


    <?php
}

This is the result I end up with. If I click the "test" link it will open in the same window. If I click the Preview link it still opens in a new tab.

Picture.png

ps: I’m using the method from Things you may not know about jQuery to check for bound events, and I didn’t find anything bound, and I believe WordPress primarily uses jQuery so I don’t think this would be bound with another event handler.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:44:33+00:00Added an answer on May 27, 2026 at 5:44 am

    You could try this:

    jQuery('.preview.button').click(function(e){
        window.location.href = this.href;
        return false;
    });
    

    Works from the Chrome Inspector.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this Can I automate creating a .NET web application in IIS? a
This was an job placement interview I faced. They asked whether we can realloc
I can enumerate many features of functional programming, but when my friend asked me
I have already asked on javascript/flash libraries for upload, which can make upload of
I can see this question (or a similar one) has been asked a few
I have asked a similar question to this one already but I think it
Alright, I know I've asked similar questions, but I feel this is hopefully a
I've asked how I can make a custom view repeat itself into several separate
I know many have asked this question, but I think my situation is a
I know this question has been asked before, but this was one and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.