If this tutorial is not what you were looking for, you still have any questions, suggestions or concerns - feel free to let us know. Please help us to serve you better!

Your Name

Your Email

Your Message (required)

captcha

Featured templates

WordPress. How to create a redirect from a home page to any URL using the PHP redirect

This tutorial is going to show you how to create a redirect from WordPress home page to any URL using the PHP redirect.

WordPress. How to create a redirect from a 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:

  1. Log into your Dashboard and go to Appearance -> Editor, select Home Page Page Template (page-home.php):

    WordPress._How_to_create_a_redirect_from_a_home_page_to_any_URL_using_the_PHP_redirect-1

    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.

  2. 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 get_header(); function:

    $location = get_site_url() . "/contact";
    wp_redirect( $location, 301 );
    exit;						

    WordPress._How_to_create_a_redirect_from_a_home_page_to_any_URL_using_the_PHP_redirect-2

    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.

  3. Save the changes to the page-home.php file by clicking on the Update File button:

    WordPress._How_to_create_a_redirect_from_a_home_page_to_any_URL_using_the_PHP_redirect-3

    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:

WordPress. How to create a redirect from a home page to any URL using the PHP redirect