Learn everything about WordPress Sitemap.xml, Attachments and Redirect Attachments to Parent Page

Last updated
App Shah

Crunchify » SEO 101 Tutorials » Learn everything about WordPress Sitemap.xml, Attachments and Redirect Attachments to Parent Page

Today on Crunchify, we have made few changes and would like to share changes to my readers. SEO is really tricky. Sometimes you need to know what are the best SEO settings and changes.

In this tutorial we will go over changes related to attachment pages, how to remove it from Sitemap.xml file and how you could redirect attachment pages to parent pages.

What is sitemap in WordPress world?

Sitemap.xml is a file consist of your list of all posts, pages, images and attachments. Do I have to have sitemap.xml? Google says – you don’t need sitemap file if your site is small. No matter what Google is going to crawl your site anyways.

Then why we need sitemap.xml?

We need sitemap.xml file if your site is very big, you have separate site structure, dedicated news blog and complex site.

On Crunchify, we are using Yoast SEO Premium plugin. It by default adds attachment pages to your sitemap.

Take a look at Post Types page under XML Sitemap:

Make sure you set Not in Sitemap option for your site. There is no point adding attachments to your sitemap. Google mainly index your dedicated page if it has some lengthy contents and some value added description.

Mainly for attachment pages there is no post contents and Google usually see no value indexing those pages.

For SEO (Search Engine Optimization) best practice it’s also advisable to redirect all individual image page to parent post.

Take a look at this:


Here first URL is a attachment page which is redirecting to it’s parent page.

Then how to redirect Attachment pages to Parent page?

There are couple of ways you could redirect attachment pages to parent page.


If you are using Yoast SEO plugin then just go to

Make sure you select Redirect option as you see in below diagram.

And you are all set. Now all your attachment pages will be redirected to Parent page.


Create file crunchify-image.php file and put below code into it.

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


There is a WordPress plugin out there called Attachment Pages Redirect which does exactly the same if you want to avoid any custom settings and you don’t use Yoast SEO plugin.

Attachment Page Redirect

What to do after making above changes?

5 thoughts on “Learn everything about WordPress Sitemap.xml, Attachments and Redirect Attachments to Parent Page”

  1. It was such a great article which was on sitemap in wordpress. I would like to add some easy points which are as follows:
    1.Search Engine Indexing
    2.Content Organization
    3.User Navigation
    4.Prioritization of Content
    5.New Websites and Blogs
    6.Large Websites
    These are some points which I wanted to include in your article.

  2. Thanks for the article. I am using Yoast on 2 of my websites. One I launched in May and the second in July. The latter doesn’t have the attachment folder in the sitemap, however, the first does.

    No one in the free version is there the option to remove media in the sitemap, like you have. I’m debating checking out a new SEO plugin!

  3. Thanks App Shah for such a wonderful article.
    Regarding the last point, how can we regenerate the sitemap.xml file? Is this functionality available within Yoast SEO?
    Best regards, Brian.


Leave a Comment