Redirect page URL to home URL without using a plugin

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');

Leave a Comment

error code: 523