• Resolved Dee

    (@supinda1985)


    I would like to add a warning message that pops up before hitting publish on posts. I have looked for plugins, but they all seem to be very outdated. I also found code to add to the functions.php file, but it doesn’t work:

    // Adding a WordPress post publishing confirmation message.

    $c_message= ' You’re about to publish this post. Are you sure that it's ready to go?';

    functionconfirm_publish(){

    global$c_message;

    echo'';

    }

    add_action('admin_footer', 'confirm_publish');

    Is there an easy way to do this? Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Make sure you add this code snippet to your theme’s functions.php file or consider using a child theme to keep your changes safe from theme updates.

    If this code still doesn’t work as expected, there might be conflicts with other plugins or themes on your WordPress site.

    Hi Dee,

    Here’s some code that you can put in your functions.php file. Note – that this doesn’t work with the Gutenberg editor – only the classic editor.

    add_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;
    }

    That puts a little script on your admin pages. When you hit publish, schedule, or update, you’ll get a confirmation message.

    Thread Starter Dee

    (@supinda1985)

    Terence you are the absolute best! Thank you so much!

    • This reply was modified 1 year, 1 month ago by Dee.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get warning message before publishing’ is closed to new replies.