# Ask Before Moving Posts to the Trash

> Shows a confirmation dialog when someone clicks "Trash" under a post, page or media item, or applies the Move to Trash bulk action, to prevent accidental removals.

- Type: PHP
- Runs: Admin only
- Category: [Admin](https://wpide.com/library/category/admin/)
- Tags: trash, confirmation, safety
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/admin-confirm-before-trash/

## Code

```php
$wpide_trash_confirm = function () {
    ?>
    <script>
    document.addEventListener( 'click', function ( event ) {
        var link = event.target.closest( '.row-actions .trash a, .row-actions .delete a, a.submitdelete' );
        if ( link && ! window.confirm( 'Move this item to the trash?' ) ) {
            event.preventDefault();
        }
    }, true );
    document.addEventListener( 'submit', function ( event ) {
        var form = event.target;
        if ( ! form.id || form.id !== 'posts-filter' ) { return; }
        var top = form.querySelector( '#bulk-action-selector-top' );
        var bottom = form.querySelector( '#bulk-action-selector-bottom' );
        var action = ( top && top.value !== '-1' ) ? top.value : ( bottom ? bottom.value : '' );
        if ( action === 'trash' ) {
            var count = form.querySelectorAll( 'tbody .check-column input:checked' ).length;
            if ( count && ! window.confirm( 'Move ' + count + ' item(s) to the trash?' ) ) {
                event.preventDefault();
            }
        }
    }, true );
    </script>
    <?php
};
add_action( 'admin_footer-edit.php', $wpide_trash_confirm );
add_action( 'admin_footer-upload.php', $wpide_trash_confirm );
add_action( 'admin_footer-post.php', $wpide_trash_confirm );
```

## Notes

Items in the trash can still be restored for 30 days; this only adds a safety prompt.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Ask Before Moving Posts to the Trash" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
