Created
February 22, 2023 12:44
-
-
Save Dapo-Obembe/e4d821bc5952139e2d650541debb2669 to your computer and use it in GitHub Desktop.
Redirect WordPress Page to Another Page Without Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read more about How to redirect wordpress page to another page without plugin here