
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:
https://crunchify.com/fix-allowed-memory-size-exhausted-wordpress/Fix-PHP-Fatal-Error-Allowed-Memory-size-Exhausted/
https://crunchify.com/fix-allowed-memory-size-exhausted-wordpress/
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.
Method-1
If you are using Yoast SEO plugin then just go to
- SEO
- Advanced
- Permalinks tab
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.
Method-2
Create file crunchify-image.php
file and put below code into it.
<?php wp_redirect( get_permalink( $post->post_parent ), 301 ); exit; ?>
Method-3
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.
What to do after making above changes?
- Regenerate your sitemap.xml file
- Resubmit it to your Google Search console

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.
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!
Hi Joe – can you check your Media Setting option?
Redirect attachment URLs to the attachment itself? I do have this set to YES. https://uploads.disquscdn.com/images/f225237b34b926505b00fc31c1442168a611de1c9ff2bf5fdf16881fa91d470d.png
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.
Hi Brian – yeah it’s available as part of Yoast SEO.