Title: [Plugin: Google XML Sitemaps] Including Attachment Pages [hack]
Last modified: August 20, 2016

---

# [Plugin: Google XML Sitemaps] Including Attachment Pages [hack]

 *  [marcus972](https://wordpress.org/support/users/marcus972/)
 * (@marcus972)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/plugin-google-xml-sitemaps-including-attachment-pages-hack/)
 * Hi,
    I was searching a quick way to include attachment pages in Google XML Sitemap
   generator plugin. I saw that all topics requesting support in order to include
   this feature in the plugin are all closed so I create this one to help those 
   who are interested in the solution I found. I am not used to create a module 
   or an additional plugin to do this so I directly hacked the original module core
   file to do the job. Here is how I did this :
 * you have to edit wp-content/plugins/google-sitemap-generator/sitemap-core.php
 * Replace (or comment out)
    `$post_types = array_diff($post_types,array("post","
   page","attachment"));` by `$post_types = array_diff($post_types,array("post","
   page"));` (near line 1144)
 * Replace (or comment out)
    `$where.=" (post_status = 'publish' AND (post_type 
   in ('','post'";` by `$where.=" ((post_status = 'publish' OR post_status = 'inherit')
   AND (post_type in ('','post'";`
 * save file then in the admin interface you will have to tick the checkbox
    **Include
   custom post type Medias** in the **Custom post types** section Save and regenerate
   sitmap
 * You will see that attachment page are now present in sitemap
 * bye

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [jkbb](https://wordpress.org/support/users/jkbb/)
 * (@jkbb)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-google-xml-sitemaps-including-attachment-pages-hack/#post-3408535)
 * Thousands thanks you my friends. I try it and success. This is what I’m looking
   for. But are you sure, it will not affect negative at site indexing? And what
   about html sitemap ( generated with plugin like dd sitemap ), is it necessary
   to be modified like sitemap.xml as well?
 * Kind regards
 *  Thread Starter [marcus972](https://wordpress.org/support/users/marcus972/)
 * (@marcus972)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-google-xml-sitemaps-including-attachment-pages-hack/#post-3408536)
 * Hi
    Glad to see that it helped somebody. No I dont think it could negatively 
   affect site indexing. You can perform check on the sitemap.xml directly with 
   Google Webmaster Tools. I dont know about any other sitemap extension. The only
   one I use is the Google XML Sitemap, but I guess it could be hacked too. The 
   purpose of this hack for me was to include attachment page in order to auto cache
   them with cache plugin like W3 Total Cache or Quickcache. Both of these extension
   have an option to automatically perform caching of page included in the sitemap.
   But in the original sitemap.xml, there was no attachment page listed.
 * Regards
 *  [jkbb](https://wordpress.org/support/users/jkbb/)
 * (@jkbb)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/plugin-google-xml-sitemaps-including-attachment-pages-hack/#post-3408538)
 * I want to add tags list from single post into attachment page. Standard code 
   like <?php $tag_list = get_the_tag_list( ”, ‘, ‘ ); doesn’t work at attachment
   page. It must be connected to its parent single post. Do you know to fix this?
   
   Also at my attachment page there are several images. Big images and thumbnail
   images. I want to display all of images name list here, but I don’t know how 
   to write code. Important to me, because my images name use keyword. Can you help
   me writing its code?
 * Very thanks you
 *  [Juneedo](https://wordpress.org/support/users/juneedo/)
 * (@juneedo)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/plugin-google-xml-sitemaps-including-attachment-pages-hack/#post-3408574)
 * [@marcus972](https://wordpress.org/support/users/marcus972/):
 * Hi, I recently implemented your hack, and yes it works as expected.
 * There’s one thing though, it also include attachments that are attached to posts
   with “draft” or “future” status.
 * And they would be listed as:
    [http://www.mydomain.com/?attachment_id=123456](http://www.mydomain.com/?attachment_id=123456)
 * Can you please help and tweak the hack a bit more to include attachments that
   are attached to published posts only?
 * Thank you so much.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘[Plugin: Google XML Sitemaps] Including Attachment Pages [hack]’ is closed
to new replies.

## Tags

 * [attachment](https://wordpress.org/support/topic-tag/attachment/)
 * [sitemap](https://wordpress.org/support/topic-tag/sitemap/)
 * [xml](https://wordpress.org/support/topic-tag/xml/)

 * 4 replies
 * 3 participants
 * Last reply from: [Juneedo](https://wordpress.org/support/users/juneedo/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/plugin-google-xml-sitemaps-including-attachment-pages-hack/#post-3408574)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
