[Plugin: Google XML Sitemaps] Including Attachment Pages [hack]
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"));
$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'";
$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
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?
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.
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
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:
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.
- The topic ‘[Plugin: Google XML Sitemaps] Including Attachment Pages [hack]’ is closed to new replies.