Categories

Featured templates

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

Guillaume Dumas August 11, 2015
Rating: 5.0. From 1 vote.
Please wait...

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

Coolest Wordpress Themes
This entry was posted in WordPress Tutorials and tagged home, page, php, redirect, WordPress. Bookmark the permalink.

Submit a ticket

If you are still unable to find a sufficient tutorial regarding your issue please use the following link to submit a request to our technical support team. We'll provide you with our help and assistance within next 24 hours: Submit a ticket

  • HAMID AWAN

    thanks. its works

    No votes yet.
    Please wait...
  • Pilot #171

    Wow! I can’t believe it was this simple. THANK YOU!

    No votes yet.
    Please wait...
Live Chat
We help you to choose the right product.