Customize Your Robots Meta Tags in Thesis

by SEO Mofo on Jan 4th, 2010

in Thesis Theme

This is a followup response to Everfluxx, who wrote a post about the robots meta tags that Thesis inserts into archive pages.

Add Noindex to Archive Pages

Everfluxx discovered that when you opt to add the noindex attribute to your pages’ robots meta tags, Thesis automatically assumes you meant noindex, nofollow. However, the nofollow attribute can cause a loss of site-wide PageRank, so many Thesis users will probably need a way to remove it. Customize your robots meta tags with Thesis

For a complete explanation, check out this must-read post from Everfluxx:
Using Thesis? Then beware of the “hidden” nofollow on archive pages!

In his post, Everfluxx describes the problem and proposes a solution. His solution is quick and easy, but it requires editing Thesis core files, which makes some bloggers nervous (since they would have to redo that code edit every time a new version of Thesis is released). In his closing paragraph, Everfluxx writes:

A final word to fellow Thesis developers/hackers: if you can think of a Better Way To Do It that does not require editing the theme files (e.g., via WP hooks, I dunno), please drop it in the comments. Thanks

I was in the mood for some php coding, so I set to work and made it happen. But…it was just too beautiful to leave as a comment…so I kept it all to myself! (Sorry, Everfluxx! If it’s any consolation, I’ve used hot pink throughout this post…in your honor! =P)

How to Customize Your Robots Meta Tags in Thesis

  1. UN-check the boxes under Add Noindex to Archive Pages in the Thesis Options menu. (The code below will add the robots meta tag for you, so if you leave the Thesis options checked…you’ll end up with 2 robots meta tags on each page.)
  2. Copy the code below and paste it into your custom_functions.php file.
  3. Edit the robots meta tag that corresponds with each page type to suit your specific needs. I have included a variety of page types already, but feel free to delete the ones you don’t need. For more-advanced customizations, reference the WordPress conditional tags.
  4. Promote this post for me by clicking the social media widgets below.
// Define your motherfuckin' meta robots tags
function my_mofo_meta_robo() {
	if (is_home())
		$mofo_robo = "<meta name=\"robots\" content=\"index, follow\" />\n"; // HOME PAGE
	elseif (is_single())
		$mofo_robo = "<meta name=\"robots\" content=\"index, follow\" />\n"; // SINGLE BLOG POSTS
	elseif (is_page())
		$mofo_robo = "<meta name=\"robots\" content=\"index, follow\" />\n"; // PAGES
	elseif (is_category())
		$mofo_robo = "<meta name=\"robots\" content=\"index, follow\" />\n"; // CATEGORY ARCHIVES
	elseif (is_tag())
		$mofo_robo = "<meta name=\"robots\" content=\"noindex, follow\" />\n"; // TAG ARCHIVES
	elseif (is_author())
		$mofo_robo = "<meta name=\"robots\" content=\"noindex, follow\" />\n"; // AUTHOR ARCHIVES
	elseif (is_date())
		$mofo_robo = "<meta name=\"robots\" content=\"noindex, follow\" />\n"; // DATE ARCHIVES
	elseif (is_search())
		$mofo_robo = "<meta name=\"robots\" content=\"noindex, follow\" />\n"; // SEARCH PAGES
	elseif (is_404())
		$mofo_robo = "<meta name=\"robots\" content=\"noindex, follow\" />\n"; // 404 ERROR PAGE

	echo $mofo_robo;
}

// Add your motherfuckin' meta robots tag to the <head> section
add_action('wp_head', 'my_mofo_meta_robo');

{ comment Leave a comment }

Everfluxx January 4, 2010 at 5:20 pm

Elegant solution, thanks for sharing! :)

I’m also flattered by the custom-colored link… Hope you don’t mind if I reciprocate. ;)

Luke Jones January 5, 2010 at 4:19 am

Thanks for the solution :).

Jen Lopez January 5, 2010 at 9:59 am

This is pretty slick. One question though, why add the index,follow though? Why not if it’s the home, single page, category, just leave it blank? I’m not sure it matters, but since that’s the default it seems unnecessary.

SEO mofo January 5, 2010 at 10:34 am

Excellent question, Jennifer Lopez!

You’re absolutely right…there is no functional difference between using <meta name="robots" content="index, follow" /> and using nothing at all.

The reason why I included those lines of code is because I wanted to provide my readers with an easy solution that doesn’t require them to add code. It’s much easier for someone to start with too much code and delete what they don’t need, rather than starting with one example and trying to duplicate it.

However, for my readers who are extraordinarily retarded…I tried to write my examples in a way that would suit most websites’ needs, on the off-chance that they just dump this code into their theme and don’t edit it at all.

Also, some readers will notice that this code doesn’t have to limit itself to robots meta tags. Therefore, if they wanted to add other elements to their pages’ head sections, they can easily edit the example code that’s already in place. For example, let’s say you needed to verify site ownership for Google Webmaster Tools. You could change this:

$mofo_robo = "<meta name=\"robots\" content=\"index, follow\" />\n"; // HOME PAGE

to this:

$mofo_robo = "<meta name=\"google-site-verification\" content=\"j3nn1f3rl0p3z157h3c00l357m0zz3r1n7h3w0rld\" />\n"; // HOME PAGE

Jen Lopez January 5, 2010 at 10:59 am

That makes sense. Although really you could also change it to this, no?:
$mofo_robo = ""; // HOME PAGE

If you were so inclined, and wanted to keep unnecessary code out of the page. Although that’s really just being nit-picky. I like this fix and am glad people are talking about it. Nothing worse than not understanding the depth of having a noindex, nofollow meta on a page.

SEO mofo January 5, 2010 at 11:56 am

In order for the newline character (\n) to work in php, it needs to be wrapped in double quotes. Since the meta tag also uses double quotes, they need to be escaped with a slash, otherwise php will interpret them as the termination of our string. I don’t want to use $mofo_robo = ""; // HOME PAGE in my example, because it invites end-users to simply paste HTML between the double quotes, which would result in an error. For example, if an end-user pasted their robots tag like this:

$mofo_robo = "<meta name="robots" content="noodp, noydir" />"; // HOME PAGE

…then php would read it like this:

$mofo_robo = "<meta name="robots” content=”noodp, noydir” />“; // HOME PAGE

Jen Lopez January 5, 2010 at 12:09 pm

I don’t want to use $mofo_robo = “”; // HOME PAGE in my example, because it invites end-users to simply paste HTML between the double quotes, which would result in an error.

That explains it. :) Thanks for your diligence in answering my questions! :D

SEO mofo January 5, 2010 at 12:13 pm

Phew! *wipes forehead*

Andy Beard January 7, 2010 at 2:01 am

This isn’t really a solution as I have pointed out on the Everfluxx post – you might as well just install an SEO plugin

It should really be done as a filter or complete function replacing the current interface with something that works.

People use Thesis for client projects – having interface elements that are broken just isn’t a viable choice.

SEO mofo January 7, 2010 at 4:24 am

I’m not sure I understand your point. You took time out of your day…to stop by my blog…just to tell me that I haven’t really found a solution…because my function doesn’t replace the Thesis admin menu?

I just want to make sure I’m understanding you correctly, before I commit to writing a 1000-word comment explaining why what you just wrote is the single-dumbest thing anyone has ever said on this website.

Hopefully, I’ve misread your comment, and what you meant to say was: “OMG! You are brilliant! This is a fantastic solution–not only to my Thesis/nofollow woes, but to every problem I’ve ever encountered! After reading this post…my sites all rank #1, my marriage is stronger than ever, and my checkbook is balanced! You are my idol, and I worship you! Long live SEO Mofo!”

If that were the case, then I wouldn’t have to write that 1000-word comment…which would be quite a relief. ‘Cause that’s a lot of words.

Everfluxx January 7, 2010 at 4:34 pm

I’d love to be proven wrong, Andy, but I’m afraid the Thesis options interface cannot be “replaced” or fixed via a single external function: months ago I looked into the Thesis source code just to realize that altering the default behaviour of that interface (e.g., introducing “nofollow” as a stand-alone option) would require rewriting the theme core. But that’s something the professional developers at DIY Themes are supposed to do, not (super-power-awesome) users like Darren. ;)

Lord Matt January 12, 2010 at 3:35 pm

So what you are saying is that something complex like this might be left for a client to tool about with and then complain when their SEO breaks? Much as I hate edit and past solutions maybe having no interface for the client might be what is needed sometimes?

Andy Beard January 7, 2010 at 4:59 am

Write the 1000 words, it might be thereputic

Long live SEO Mofo!

p.s. Interesting choice on the new logo – display none rather than something using negative offset

SEO mofo January 7, 2010 at 4:16 pm

Are you suggesting Google understands display:none;, but not position:relative; bottom:999999999em;?

Andy Beard January 12, 2010 at 10:14 am

I know 10+ different ways of doing it, I haven’t got data stating Google prefers one method over another other than if there is an image link and then a separate text link they might take the text link in preference, and if it is nofollowed you might be screwed – need more tests.

Skraggy May 10, 2010 at 1:46 am

Am I the only one that noticed : “j3nn1f3rl0p3z157h3c00l357m0zz3r1n7h3w0rld\” ;d

Prasenjit April 5, 2011 at 10:38 pm

How do I add custom robots meta tags in thesis?

Suppose if I want to add the below lines?

User-agent: *
# disallow all files in these directories
Disallow: /cgi-bin/
Disallow: /wp-admin/
Disallow: /wp-includes/
Disallow: /wp-content/
Disallow: /go/
Disallow: /recommend/
Disallow: /tags/
disallow: /*?*
Disallow: /wp-*
Disallow: /comments/feed/

Leave a Comment