Is Google Indexing your Attachment Pages

I noticed that WordPress was creating alot of attachment pages for every image that was being uploaded or inserted into a page/post.

These pages either took the format;

a) website.com/attachment_id?2734
b) website.com/category/image-name/

Google was indexing all of these attachment pages.

Why would you want to keep these pages out of Google’s index?

These page have little unique content or value to Goolge, and are merely pages with a solitary picture on them.

If you are running the WordPress SEO plugin from Yoast or the Attachment Pages Plugin these already allow you to 301 redirect attachment pages back to the main page. If neither of these solutions work for you then you could simply write a few lines of code and drop these pages from the index and not have a 301 redirect.

Below are two manual code solutions that should work. Either try the code in your main theme ‘Header’ file or ‘Functions’ file.

1. Header.php

Just add this code to your header.php file.

<?php
if(is_attachment()) {

echo '<meta name="robots" content="noindex" />';

}
?>

2. Functions.php

Or Just add this to the bottom of your function.php file.

<?php
function attachmentpages_noindex() {
if(is_attachment()) {

echo '<meta name="robots" content="noindex" />';

}
}
add_action('wp_head', 'attachmentpages_noindex');
?>

Make sure to review the source code of your pages to check that the code is rendered in the appropriate files. Google will drop these pages in time.



Leave a Reply

Michael Wall

Michael Wall is an experienced web developer based in Belfast N.Ireland currently running his own web design company.

Michael Wall is available for Internet Marketing, Google Adwords PPC and SEO work. Please call Belfast 02890 225729 or use the contact form.

Google Partner

Popular Posts

SEO training in Belfast