Skip to content

Instantly share code, notes, and snippets.

@jonbish
Created October 22, 2012 17:18
Show Gist options
  • Save jonbish/3932723 to your computer and use it in GitHub Desktop.
Save jonbish/3932723 to your computer and use it in GitHub Desktop.
301 Redirect trashed posts to the home page instead of a 404 page
<?php
/*
Plugin Name: Trash Redirect
Description: 301 Redirect trashed posts to the home page instead of a 404 page
*/
add_action('template_redirect', 'trash_redirect');
function trash_redirect(){
if (is_404()){
global $wp_query, $wpdb;
$page_id = $wpdb->get_var( $wp_query->request );
$post_status = get_post_status( $page_id );
if($post_status == 'trash'){
wp_redirect(home_url(), 301);
die();
}
}
}
@brokenfunction
Copy link

It's no working for me ;(
Maybe i need additional settings?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment