Create WordPress Page that redirects to another URL

Solution for : Create WordPress Page that redirects to another URL

we can accomplish this two ways, both of which need to be done through editing our template files.

The first one is just to add an html link to our navigation where ever we want it to show up.

The second (and my guess, the one we're looking for) is to create a new page template, which isn't too difficult if we have the ability to create a new .php file in our theme/template directory. Something like the below code should do:

 

/*  
Template Name: Page Redirect
*/ 

header('Location: http://www.name-of-new-site-where-we-have-to-redirect.com');
exit();

Where the template name is whatever we want to set it too and the url in the header function is the new url we want to direct a user to. After we modify the above code to meet our needs, save it in a php file in our active theme folder to the template name. So, if we leave the name of our template "Page Redirect" name the php file page-redirect.php.

After that's been saved, log into our WordPress backend, and create a new page. we can add a title and content to the body if we'd like, but the important thing to note is that on the right hand side, there should be a drop down option for we to choose which page template to use, with default showing first. In that drop down list, there should be the name of the new template file to use. Select the new template, publish the page, and we should be golden.

No comments:

Post a Comment