Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

A lot of my theme's image pages are ranking on Google. I'd like to remove these pages entirely from my theme so they no longer rank. When a user hits these image pages the content is taken out of context and looks very confusing.

Here is an example of a ranking image page: http://www.barbadospropertylist.com/2011/08/stephanie-barnes-interior-design-studio/cei_5346/

That image is part of blog post at: http://www.barbadospropertylist.com/2011/08/stephanie-barnes-interior-design-studio/

share|improve this question
add comment

2 Answers

Google is finding those pages because you're linking to them. Most likely this happens when you use the media uploader and hit the "insert into post" button. Unless you tell it otherwise, WP will link to the attachment page intead of the image file. So head to your pages and remove the links to attachment pages.

I would not recommend you prevent google bot from indexing your images (as one answer suggests), that is not the issue. Plus getting traffic from image search is not a bad thing.

If you're using a sitemap, ensure that the sitemap is not including the attachment pages.

After you've removed the links to attachment pages, you can "disable" attachment pages by hooking into template redirect like so:

<?php
add_action( 'template_redirect', 'wpse27119_template_redirect' );
function wpse27119_template_redirect()
{
    // get out of here if we're not headed to an attachment page    
    if( ! is_attachment() ) return; 

    // Find the $post variable representing the page where we're heading
    global $post;
    if( empty( $post ) ) $post = get_queried_object();

    // Find the permalink of our parent post
    $link = get_permalink( $post->post_parent );

    // redirect to the parent page
    wp_redirect( $link, 301 );
    exit(); // always call exit after wp_redirect
}

As a plugin: http://pastie.org/2443854

share|improve this answer
add comment

There are a few options you can choose. Depending on how your theme is set up.

If I understand you correctly, you want to remove the page that you go to when the image is clicked, correct? If so, do you want to remove the link all together?

To remove the links to your images, you can do it a few ways. If the images are added via the post/pages manager you can navigate to the post that contains the image. Go to the post editor for the post that has the image, click on the image to bring up the edit/delete icon in the top left corner of the image. Click the icon that is next to the delete icon. You will now see some dialogue boxes. Where it says "Image Links To" click the none button and click update. Now update the post or page. (This will remove any links to the files).

To remove the URL's that are already indexed, the easiest way is to set up a Google Webmaster Account. It's not required, but is the optimal way. What you will need to do is adjust the robots.txt file. To remove all images from being indexed you will add this to the robots.txt file:

User-agent: Googlebot-Image
Disallow: / 

To block only certain image directories, you would use this or something similar:

User-agent: Googlebot-Image
Disallow: /images/

You can read more about it in the WP Hacks article found here: http://wphacks.com/how-to-prevent-google-from-indexing-your-images/

Or from the Google Webmaster Page Here: http://www.google.com/support/webmasters/bin/answer.py?answer=35308

To remove all attachment pages by re-directing them to the parent page, you might try this:

1) Create a new PHP file

2) Paste this line in it :

<?php wp_redirect(get_permalink($post->post_parent)); ?>

3) Save the file as "image.php"

4) Upload it into your theme folder

SOURCE: http://wordpress.org/support/topic/disable-attachment-posts-without-remove-the-medias

Hopefully that covers what you're asking. If I'm missing your point, please clarify and I'll try again to assist you with your question.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.