I want to open javascript message "Are you sure you want to move the post to trash?"when we clicks on "Move to Trash" link in Publish box. and when we click to OK the post go to trash or cancel to go back to the post.

I found this code on previous question. It's open the javascript message but when I click OK it's just close the popup and don't move the post to trash. What can I add to fix it?


if (! empty($GLOBALS['pagenow']) && 'post.php' === $GLOBALS['pagenow'])
    add_action('admin_footer', 'trash_click_message');
function trash_click_message() {
    echo <<<JQUERY
    jQuery(function($) {
        $('#delete-action a').unbind();
        $('#delete-action a').click(function(event) {
            alert('Are you sure you want to move the post to trash?');
                function() {
                    $('#save-action .spinner').hide();

Picture of my actuel result

enter image description here


Thanks bergire! It's all most done. I just have one issues. I use Wordpress in english but the serveur is on France. So the confirmation popup is in french like you see in the picture.enter image description here

Is it a way to change labels to (indique) and (annuler) words?


You can try to admin enqueue this script, with jquery dependency:

jQuery( function($) {       
    $('.edit-php a.submitdelete, .post-php a.submitdelete').click( function( event ) {
        if( ! confirm( 'Are you sure you want to move the post to trash?' ) ) {

where we restrict the conformation on the a.submitdelete clicks to the .edit-php and .post-php body classes.

Hope you can adjust it to your needs, e.g. regarding i18n.

  • thanks Birgire. can you check the update of the post please?
    – sampaii
    Jul 3 '17 at 13:56
  • You're welcome. Maybe this can help?
    – birgire
    Jul 3 '17 at 17:05
  • Any luck you had it working on the Gutenberg edit page too?
    – Tim
    Oct 14 '20 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.