Ecommerce Shopify WordPress Discussion

Adding a Confirmation Alert Before Publishing WordPress Posts

I'm working on a WordPress website, and I'd like to implement a confirmation alert that appears before publishing a post. The goal is to prevent accidental publishing and allow users to confirm their intention to publish a post. I get the confirmation dialog box , but it saves the post doesn't matter if I select cancel or OK . This is the code I am using inside functions.php function add_confirmation_script() { global $post_type; // Check if we're in the post editor and it's not a new post if ('post' === $post_type ) { ?> <script> jQuery(document).ready(function($) { $(document).on('click', '.editor-post-publish-button', function(event) { if (!confirm('Are you sure you want to publish this?')) { event.preventDefault(); // Prevent the default action (post publish) } }); }); </script> <?php } } add_action('admin_footer', 'add_confirmation_script');
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.