How could I change the redirect location after a user trashes a page? Right now they go to all pages here:....wp-admin/edit.php?post_type=page

I want them to go here:......wp-admin/edit.php?post_type=page&page=custom_page_order


Hook into load-{screen_id} and check if the $_GET['trashed'] variable is 1 or above.

function wpse_trashed_redirect(){
    $screen = get_current_screen();
    if('edit-page' == $screen->id){
        if( isset($_GET['trashed']) &&  intval($_GET['trashed']) >0){
            $redirect = add_query_arg(array('page'=>'custom_page_oder', 'trashed' => false, 'ids' => false ));

This works - and I'm not aware of a better way of doing this...

  • I think this is close. I get this url:/wp-admin/edit.php?post_type=page&trashed=1&ids=112&page=custom_page_oder It needs to be: wp-admin/edit.php?post_type=page&page=custom_page_order – Shae May 22 '12 at 20:08
  • I can't get it to remove the trash id from the URL? Any ideas? – Shae May 24 '12 at 12:24
  • I just edited the answer to make it remove ids and trash variable from the redirected url – Shazzad Dec 11 '13 at 16:32
  • If not obvious, if('edit-page' == $screen->id).. would change to if('edit-book' == $screen->id) if 'book' is your custom post type – JJ Rohrer Apr 30 '19 at 14:17

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.