Skip to content

Instantly share code, notes, and snippets.

@shizhua
Created February 20, 2016 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shizhua/75695d1e71d6ede29d73 to your computer and use it in GitHub Desktop.
Save shizhua/75695d1e71d6ede29d73 to your computer and use it in GitHub Desktop.
Redirecting 404 to any page in WordPress
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>
<?php
function redirecting_404_wp() {
global $wp_query;
if ($wp_query->is_404) {
wp_redirect( get_bloginfo('url'), 301 );exit;
}
}
add_action('wp', 'redirecting_404_wp', 1);
;?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment