How to Redirect a WordPress Page

redirect a WordPress page without plugins

The first way to redirect a WordPress page without redirecting plugins you need to add some code snippets to the functions.php the main WordPress functions file that is located in your WordPress theme.

Inside your WordPress theme, you should locate this file that is named functions.php.

This file adds all the functions to your WordPress theme and by extension your WordPress site.

Open the functions.php file and add the following code replacing the ‘about’ with your respective page which you want to redirect the users to.

Redirect a WordPress Page Without Plugins (WP_Redirect)

add_action('template_redirect', 'redirect_to_home_from_about_page');

function redirect_to_home_from_about_page() {

  if( is_page('about')) {

      wp_redirect(home_url());

    exit();
  }
}

This code checks if the user is on the About page and if they are on the About page they are redirected to the home page.

You can change this to check any other page by changing the ‘about’ string that checks if the user is on the About page. For example, we can alter the code and check if the user is on the ‘contact’ page as follows :

add_action('template_redirect', 'redirect_to_home_from_about_page');

function redirect_to_home_from_about_page() {

  if( is_page('contact')) {

      wp_redirect(home_url());

    exit();
  }
}

Redirect a WordPress Page Without Plugins (HTACCESS)

An alternative way to redirect a WordPress page without using plugins is adding a redirect rule to the htacess file that is located in the root of your WordPress installation.

If you cannot locate this file, consider checking the permissions since the file is mostly hidden on your server. Open the file and add the following code replacing the URLs for the old and new pages respectively :

RewriteEngine On
Redirect 301 /old-post/ http://yoursite.com/new-post/

Similar Articles

Comments are closed.