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?

2 Answers 2


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?
    – Samuel
    Commented Jul 3, 2017 at 13:56
  • You're welcome. Maybe this can help?
    – birgire
    Commented Jul 3, 2017 at 17:05
  • Any luck you had it working on the Gutenberg edit page too?
    – Tim
    Commented Oct 14, 2020 at 9:37
function confirm_delete_popup() {
    global $pagenow;

    // Verifica si estás en una página que comienza con "edit.php"
    if ($pagenow === 'edit.php' || strpos($pagenow, 'edit.php?') === 0) {
        echo <<<JQUERY
jQuery(document).ready(function($) {
    // Agrega un evento click a los enlaces de eliminación en páginas de edición
    $(document).on('click', '.submitdelete', function(e) {
        e.preventDefault(); // Evita que el enlace se ejecute inmediatamente
        // Muestra un cuadro de diálogo de confirmación
        var respuesta = confirm("¿Estás seguro de que deseas borrar permanentemente esta página o post? Esta acción no se puede deshacer.");

        // Si el usuario hace clic en "Aceptar", redirige al enlace original
        if (respuesta) {
            window.location.href = $(this).attr('href');

// Ejecuta el código solo en las páginas que comienzan con "edit.php"
add_action('admin_footer', 'confirm_delete_popup');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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