Last active
December 29, 2015 16:19
-
-
Save infn8/7696301 to your computer and use it in GitHub Desktop.
301 Redirect template for wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Template Name: Redirect | |
*/ | |
if(! empty($url = get_post_meta(get_the_id(), 'redirect', true))){ | |
header("HTTP/1.1 301 Moved Permanently"); | |
header("Location: ". $url); | |
die(); | |
} | |
?> | |
<html> | |
<head> | |
<title>Danger Will Robinson, Danger</title> | |
</head> | |
<body> | |
<h1>Something is wrong. </h1> | |
<p>Please set a Custom field called 'redirect' with the value of the URL you want to redirect to. <a href="http://codex.wordpress.org/Custom_Fields">More info here.</a> </p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To Use This Properly
redirect.php
in your theme's root folder.your-site.com/cool-page/
If you want to redirect the homepage then set the homepage to use that page in the Options > Reading setting in the admin panel http://your-site.com/wp-admin/options-reading.php
More info here http://codex.wordpress.org/Creating_a_Static_Front_Page