You may not realize, but every time you upload something to your Media on WordPress a new “attachment” post is also created, and these posts are automatically indexed by search engines.

It may sound like it’s not a big deal, but aside from possibly publicizing some content that you would prefer to keep private these attachment pages are basically devoid of all useful info and make you look bad in the search engines eyes, not to mention the person who is doing the search and gets taken to a lame page with nothing useful on it.

So, here’s how you hide your attachment pages from search engines:

1. If you haven’t already, create a child theme for your WordPress site.  If you’re not sure how to do this, read this previous blog post.

2. If an attachments.php file already exists in your child theme go straight to step #3, otherwise create one for your child theme and put the usual loop in it, it should look something like this:

<?php
get_header(); ?>
<div id=”container”>
<div id=”content” role=”main”>
<?php
/**
* Run the loop to output the attachment.
* If you want to overload this in a child theme then include a file
* called loop-attachment.php and that will be used instead.
*/
get_template_part(‘loop’, ‘attachment’);
?>
</div><!– #content –>
</div><!– #container –>
<?php get_footer(); ?>

3. Add a no-follow, no-index line so that the search robots know not to look at this stuff.  Here’s the line:
<meta name=”robots” content=”noindex, nofollow” />

And here’s where it should go:

<?php
get_header(); ?>
<div id=”container”>
<div id=”content” role=”main”>
<meta name=”robots” content=”noindex, nofollow” /> <–RIGHT HERE
<?php
/**
* Run the loop to output the attachment.
* If you want to overload this in a child theme then include a file
* called loop-attachment.php and that will be used instead.
*/
get_template_part(‘loop’, ‘attachment’);
?>
</div><!– #content –>
</div><!– #container –>
<?php get_footer(); ?>

Voila!