This tutorial is going to show you how to create a redirect from WordPress home page to any URL using the PHP redirect.
In order to add a redirect function to your WordPress template, you should perform the following:
Log into your Dashboard and go to Appearance -> Editor, select Home Page Page Template (page-home.php):
If you don’t have the Home Page page template in your theme folder, you should copy it there. To do that, you need to copy the file page-home.php from the directory wp-content/themes/CherryFramework to wp-content/themes/themeXXXXX.
Let’s, as an example, redirect our home page to the contact page. In order to do that, add the following code right before the
$location = get_site_url() . "/contact"; wp_redirect( $location, 301 ); exit;
You can assign any internal/external location to the $location variable. If it’s an internal location, you should append a call to the get_site_url() function before the slug as shown in the example above.
Save the changes to the page-home.php file by clicking on the Update File button:
Now when you enter your home page URL, it will automatically redirect to another page. Feel free to apply this method to any of your page templates besides the Home Page page template.
Feel free to check the detailed video tutorial below: