How to Add Confirmation Message Before Publishing a Post in WordPress
Sometimes it happens that we hit the button ‘Publish‘ accidentally in WordPress and the post that was being written gets publish immediately. In this way, it’s not good for our site visitors to reach on an incomplete article. So, I decided to solve this problem for those who are having this problem. Finally, I figured out and came across a wonderful solution to add confirmation message before publishing a post in WordPress.
Confirmation Message Before Publishing a Post
It’s a pop-up message that appears when you go to Publish the article on your WordPress blog. And if you also looking to prevent accidentally publishing article in your WordPress blog then you should read this article about adding a confirmation message before publishing a post.
When you hit the “Publish” button after writing a post, a small dialog box appears asking you if you’re sure you want to publish the post. You can either click OK or CANCEL. And that’s it! Super simple and no more accidentally published posts.
To add the confirmation message simply install and activate Publish Confirmation in your blog. This will work like a charm and there are not configuration settings. Or if you don’t want to increase the number of plugins in your blog due to high resource usage or due to any other reason simply add the following code in your functions.php file:
$c_message = 'Are you SURE you want to publish this post?'; // This is the confirmation message that will appear. function confirm_message_publish(){ global $c_message; echo ' <script type="text/javascript"><!-- var publish = document.getElementById("publish"); if (publish !== null) publish.onclick = function(){ return confirm("'.$c_message.'"); }; // --></script>'; }
add_action('admin_footer', 'confirm_message_publish');
That’s fine for now, and whenever you go to publish new article you will see the following message before getting your article published: