Skip to content

Instantly share code, notes, and snippets.

@Dapo-Obembe
Created February 22, 2023 12:44
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 Dapo-Obembe/e4d821bc5952139e2d650541debb2669 to your computer and use it in GitHub Desktop.
Save Dapo-Obembe/e4d821bc5952139e2d650541debb2669 to your computer and use it in GitHub Desktop.
Redirect WordPress Page to Another Page Without Plugin
IF you want to learn how to redirect a WordPress page to another page or WordPress 404 page to another page WITHOUT PLUGIN, you are in the right place.
Read the detailed article here: https://www.alphawebtips.com/how-to-redirect-wordpress-page-to-another-page-without-plugin/
##SEE Code below:
//TEMPLATE REDIRECT
function redirect_to_page() {
if(is_page('PAGE ID HERE')) {
wp_redirect(site_url('URL-HERE'));
exit();
}
}
add_action('template_redirect', 'redirect_to_page');
##To Redirect WordPress error 404 page to HOmepage, use the function below:
//TEMPLATE REDIRECT 404 to home page
function redirect_to_page() {
if(is_404()) {
wp_redirect(site_url('/')); //OR use wp_redirect(home_url());
exit();
}
}
add_action('template_redirect', 'redirect_to_page');
@Dapo-Obembe
Copy link
Author

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