Thesis 1.7 has a sweet new post option that allows you to redirect any single post or page to any URL on the web. This is great for affiliate links along with a plethora of other uses. One problem. You can only redirect single posts and pages. What if want your archived (tag, author, date, category) pages to redirect somewhere? What if you want to redirect your 404 error page back to your homepage? I have a solution!
How 301 Redirects Work
A 301 redirect is basically just one line of code that tells a browser to go to a different URL than the one it is currently loading. Typically, you find these redirects at or near the top of the web page’s code. When the browser reads the code, it stops loading the page, and heads over to the URL its been redirected to. Simple! This is exactly what happens when you use the Thesis post option to redirect a single post or page to another URL.
The Code
This is really very simple. We’re going to use conditional tags, a native WordPress function, and a native WordPress hook. Theoretically, you could apply this exact same code to absolutely any WordPress theme and it should work! To demonstrate how this is done, let’s redirect your 404 error page to your homepage. Here’s the code:
function simple_redirect() {
if(is_404()) {
wp_redirect( 'http://www.yoursite.com', 301 );
}
}
add_action('template_redirect', 'simple_redirect');
The Breakdown
That’s all there is to it! Here’s what we did:
- We created a wordpress function called “simple_redirect” to house the code
- We use the conditional tag
if(is_404())to state that this redirect will only occur if this is the 404 error page - We use
wp_redirectto indicate the URL we are redirecting to, and to designate that this is a 301 redirect - We use the WordPress hook
template_redirectto hook our function
template_redirect places our function before any template (read: Thesis) files are loaded. This means our redirect won’t conflict with any of the header information that Thesis calls. All that’s left to do is copy and paste that code into custom_functions.php.
It really is that simple. Now you have total control over the route your visitors take when they come to your site!
Take Action Now!
- Choose the proper conditional tag for the page you wish to redirect
- Be sure to enter the correct URL you are redirecting to
- Copy and paste the code into custom_functions.php in your Thesis "custom" folder
Get Free Updates From Art Of Blog
Sign up to receive insider tips only available to our email subscribers.
You can also subscribe to our RSS feed or follow us on Twitter to get the latest updates. Check out our YouTube channel for the latest video tutorials!





Thesis 1.8 and Genesis 1.3 Compared
Two Sure-Fire Ways to Increase Website Traffic
Thesis Recent Tweets with @Anywhere Integration
Add A Tweet This Post Box To Your Thesis Post Footer
WordPress Security 101: Securing your Site
Using WordPress Pages like a Pro
Thesis Review: Thesis WordPress Theme Video Review
Enable Your Fans – Top Community Building and Social Sharing Tools for Your Blog
15 Incredibly Useful WordPress Plugins to Make Your Life Easier
What’s in It for Me: 7 Types of Timeless Core Content
{ 2 comments… read them below or add one }
thank you ———- ive been searching like crazzy 4 this code.
and works ok
Your the man!!!!!!!!
Thank for the code
{ 2 trackbacks }