Publish Confirmation For WordPress Classic (2023)


Here's a quick scrap of code that works. There are lots of outdated tutorials out there for old versions of WordPress. This one is tested to be working in WordPress 6.3.2. This will pop up a confirmation dialogue when you try to publish, update, or schedule a post or page.

The Code

Add this to your theme's functions.php file:

PHP PHPadd_action( "admin_footer", "confirm_publish" );
function confirm_publish() {
    echo <<< EOT
    <script>
        var publishButton = document.getElementById("publish");
        if (publishButton !== null) {
            publishButton.onclick = function(event) {
                event.stopImmediatePropagation();
                var publishValue = publishButton.value;
                return confirm("Do you want to " + publishValue + " this now?");
            };
        }
    </script>'
    EOT;
}

Screenshots

Screenshot of a page asking for confirmation before publishing. Screenshot of a page asking for confirmation before updating. Screenshot of a page asking for confirmation before scheduling.

Limitations

  • Only for WordPress's classic editor. Won't work in Gutenberg.
  • English only. Feel free to translate into other languages.
  • After confirmation, your browser may say "This page is asking you to confirm that you want to leave — information you’ve entered may not be saved." - I don't know how to stop that.

Share this post on…

  • Mastodon
  • Facebook
  • LinkedIn
  • BlueSky
  • Threads
  • Reddit
  • HackerNews
  • Lobsters
  • WhatsApp
  • Telegram

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <p> <pre> <br> <img src="" alt="" title="" srcset="">