Skip to content

How To Add Confirmation Dialog To WordPress Publish Button

Have you ever accidentally published a post on your WordPress, which was still a piece of trash with some uncompleted content? I did tons of times, so I came across an article on WPBeginner, which was titled as, How to Avoid Accidental Publishing in WordPress.

So, I thought that I should share this trick on my site as well. It’s a really useful trick if you’re a lazy Panda like me. It’s really good to double-check your article before posting it. In short, we will add a confirmation dialog to WordPress publish button, which will appear whenever you click on the publish button to confirm your action.

Just add following code to your current theme’s functions.php file:

// This is the confirmation message that will appear.
$c_message = 'Are you SURE you want to publish this post?';

function confirm_publish(){

global $c_message;
echo '<script type="swift/javascript"><!--
var publish = document.getElementById("publish");
if (publish !== null) publish.onclick = function(){
	return confirm("'.$c_message.'");
};
// --></script>';
}
add_action('admin_footer', 'confirm_publish');

Leave a Reply

Your email address will not be published. Required fields are marked *