How do I redirect this page URL, http://localhost/wordpress_rnd/?page_id=2
, to the home URL, http://localhost/wordpress_rnd/
, without using any plugins?
4 s
The correct way to do this is using the template_redirect
hook by adding a function to your functions.php
:
function redirect_to_home() {
if(!is_admin() && is_page('2')) {
wp_redirect(home_url());
exit();
}
}
add_action('template_redirect', 'redirect_to_home');