I want to open javascript error message when some one clicks on "Move to Trash" link in Publish box in wp-admin


1 Answer 1


Put the following in your functions.php:

if (! empty($GLOBALS['pagenow']) && 'post.php' === $GLOBALS['pagenow'])
    add_action('admin_footer', 'trash_click_error');
function trash_click_error() {
    echo <<<JQUERY
    jQuery(function($) {
        $('#delete-action a').unbind();
        $('#delete-action a').click(function(event) {
                function() {
                    $('#save-action .spinner').hide();
  • Thanks for your help. I think we are very close to do it. I used 'wp_trash_post' instead of 'admin_footer'. It goes in this function but I am not able to get the alert box. Can you please help me to sort out it.
    – Xing Lee
    Apr 22, 2013 at 11:41
  • Well, that is beacuse the hook is the wrong one. If you don't want to use admin_footer (whatever the reason may be), use admin_head with a priority of 999 or something like this. Why is that so? We are injecting some jQuery code (to the website's source code) that then is affecting the link. There's no sense in doing this after the link has already been clicked (which is when you hook action is fired).
    – tfrommen
    Apr 22, 2013 at 11:57
  • Hi,I need to apply same thing on Trash link on posts listing page. Any help much appriciated
    – Xing Lee
    May 3, 2013 at 7:34

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.