Thesis Tip: Hide 301 Redirects From Search Results

by derek on January 10, 2011 · 12 comments

One of the features that I have really come to love about the Thesis theme is the ability to easily create 301 redirects without the need to tinker with the .htaccess file or install a plugin.

Creating a Thesis 301 redirect

As you can see above, all you need to do is create a new WordPress page with your desired title and then scroll down to the SEO Details and Additional Style section and enter in the desired destination URL in the 301 Redirect for this Page’s URL text box. You don’t need to enter any content for the page as the URL will simply be redirected to the specified destination.

What are all these blank search results?

While utilizing the 301 redirects offers a seamless way to quickly add friendly affiliate links (some might say masking affiliate links), there is one drawback that you can see below – by default the WordPress search results include pages and thus all of your empty redirects are displayed in the search results.

Thesis 301 Redirect Search Results

This isn’t a huge problem as the links do still redirect properly, but having these empty results displayed among your relevant post is not exactly user friendly – nor does it look that great.
Fortunately I have a fix for you!

Quick…grab a filter

The good news is that we can easily resolve this issue by adding a simply filter to our custom functions file in the Thesis theme that will exclude pages from being returned in the search results.
function removePages($query) {
if ($query->is_search) {
return $query;
Now this might seem daunting for some that aren’t comfortable editing your custom PHP files, but it is really quite simple. All we are doing is applying a filter that checks if we are performing a search query and then setting the “post_type” of the query to only return the “post” type.
All you need to do is open your custom_functions.php file and paste the above code snippet. Save the file and try a search.
No more empty pages displayed in your search results!

Need a hand?

While implementing this change is piece of cake for those of us that don’t sweat at the thought of even opening up the code let alone tweaking PHP code, I am well aware that some people just might not be comfortable making this change on their own.
In the event that you would prefer someone to help you out with making this – or any other change to your Thesis website – leave a comment here or contact me for help.

Stay In The Loop!

Subscribe to the Derek Semmler dot com feed via RSS or Email to receive notifications when new posts are published. Follow the WordPress ninja on Twitter too!

{ 11 comments… read them below or add one }

Justin Germino January 10, 2011 at 9:07 am

Excellent tip for those not wanting 301 redirected pages in search results, I am still using my .htaccess file manually myself. The Redirection plugin for Wordpress lets people do the same thing for their blogs for those who are not on Thesis.


derek January 10, 2011 at 11:48 am

Thanks for the feedback Justin! I too have a mixture of sites where some are still using the .htaccess for redirects while others use a plugin, but for those using Thesis to handle them I think this is one of the small details many don’t notice. Taking a quick look around at a handful of other Thesis sites, I noticed the same issue occurring.
Thanks again!


Raffaello Tamagnini January 10, 2011 at 10:02 am

thanx for your useful tips its good to have these resources on line. keep updating your post


Eren Mckay January 10, 2011 at 10:27 pm

Thesis has a way of making it very easy for people to do lots of things. I’ve thought of switching over but I’m so totally used to my Lifestyle Theme that I don’t think I can.
Whenever I make any changes in my php, I make sure to copy and paste the entire backup document of it in case something goes wrong. I also don’t do anything else so that my mind is fully concentrated and I don’t mess up. I have had a few encounters with php mess ups never to do that again.
Glad to see you posting again.
All the best,


derek January 10, 2011 at 11:42 pm

Thanks for the comment Eren!
You’ve made a great point about making a backup of your file before you begin making changes. I’ll admit that I rarely do that myself, mostly because writing code is second-nature to me. But there have been times where I accidentally messed things up and had to scramble to fix it.
If things are working with your theme and you’re happy, stick with it. I just refreshed the theme on my personal finance site as it was still using the MistyLook theme! For the last few years I knew the theme was out dated but there was no real compelling reason to change.
Thanks again for the note. If there is ever any specific topic you would like to see here, please speak up. 🙂


SteveSildon@Credit Card Assist January 20, 2011 at 1:41 am

Very nice hack Derek. Thesis rocks … I’m converting another one of my blogs over to Thesis and plan on running exclusively from here on out. Having to fiddle with the .htaccess file is always frightening.


derek January 20, 2011 at 1:45 am

I’ve been really happy with Thesis and have done quite a bit with it on a variety of different sites. I’d love to see the site once you have it converted over.
I had just commented to someone today with a way to do a redirect in the htaccess file but noted that many people find editing that file to be terrifying.
Thanks for the comment Steve!


Steve Sildon January 20, 2011 at 2:40 am

If you’ve ever screwed up an .htaccess file, you fully understand why people are so terrified of fiddling with it. Any tool that allows me to steer clear of ANY fiddling with htaccess is a big deal. One of the best pieces of add-on functionality that Chris and DIY have added to Thesis, IMHO.


derek January 20, 2011 at 5:40 pm

True. As is the case with most files, but particularly the htaccess file, make a backup before you do anything! 🙂


Joe July 19, 2011 at 6:23 am

I am hoping you can answer a question for me. Since my conversions are down I created a landing page that I want to redirect as many of my pages as possible to. I have links coming into every page and post on my blog including the main URL.
I use the flexibility theme and I use the 301 simple redirect and wondering if there is anyway I can redirect my main URL and other post directly to my landing page without getting hurt in Google.
I know how to do the redirect as that is simple enough, wondering what ill effects it will have in Google and how to avoid them.


Brian Kinkade@boulder homes August 9, 2011 at 6:32 am

So nice of you to offer help. I am planning to put up another site using Thesis theme and the information you have here sure is useful. I’ll contact you just in case I encounter any problems with the codes. Thanks!


Leave a Comment

{ 1 trackback }

Previous post:

Next post: