Lee Willis

Adding Post Thumbnails To Your Sitemap

| 20 Comments

Google recently blogged about Adding Images to your Sitemaps. When I read this my thoughts jumped straight to a friend’s site that is image-orientated, and could really benefit from this. His site uses WordPress’ post thumbnails to store an image against each post, and I wanted to get those images into his sitemap.

His site already uses the great Google XML Sitemaps plugin to auto-generate an XML sitemap, so I thought I’d have a go at extending it to support post thumbnails.

The resulting XML looks a little like this:

<url>
  <loc>http://test.leewillis.co.uk/hello-world/</loc>
  <image:image>
    <image:loc>http://test.leewillis.co.uk/wp-content/uploads/test.jpg</image:loc>
    <image:title>Hello world!</image:title>
    <image:license>http://test.leewillis.co.uk/license/</image:license>
  </image:image>
  <lastmod>2010-04-14T21:15:15+00:00</lastmod>
  <changefreq>monthly</changefreq>
  <priority>1.0</priority>
</url>

Some notes on the above. The image title is set the same as the post’s title – which I figure should be a reasonable result, from a user and SEO point of view. The license URL is configurable (One per site).

I’ve submitted the code to the plugin author to hopefully get included, but if you can’t wait, there’s a patch file available here – just apply it with the “patch” utility.

20 Comments

  1. Hi Lee – I’m using cygwin to apply the patch but keep getting errors and the patch is rejected.

    I’ve been running the following command once in the directory where sitemap.php

    c:\cygwin\bin\patch.exe -p0 < c:\image_url.diff

    Do you have any suggestions or know what I could be doing wrong?

    Thanks!

    • Hiya – the patch includes the directory itself, so you probably want -p1, e.g.

      c:\cygwin\bin\patch.exe -p1 < c:\image_url.diff

      Let me know how you get on.

      • Hi Lee – I tried that and still got the 11 out of 11 hunks failed error … I’ve never used the patch utility before so am unsure what should happen. Although I did get it to run – lol. I guess I’ll just have to hope that it gets added to the plugin.

        Thanks for your help!

        • Hmm – not sure why that would fail. I’ve put up a ready-to-go version of the plugin here:

          http://www.leewillis.co.uk/patches/google-sitemap-generator/post-thumbnail-images/google-sitemap-generator.zip

          Give it a whirl and let me know how you get on.

          • Thanks for the file. I’m replaced the plugin with this but it doesn’t seem to be adding the image information to the sitemap. I played around with it a little yesterday and made sure all the entries had thumbnails so, again, I’m stumped.

            I appreciate all your help and am afraid I’m becoming a bother.

          • Make sure you’ve ticked the box in the plugin settings to include post thumbnails – I probably should have mentioned that :)

            It’s down in the “Sitemap Content” section. Tick that, save your settings, rebuild your sitemap and you should be good to go.

            It’s also worth mentioning that the post images aren’t shown in the “HTML” view of the sitemap (The stylesheet just ignores them), but if you view the actual file you should see the entries there.

            If you’re still having no joy I’d be glad to help you get it up and running – drop me note via the Contact page.

          • Thanks again – boy, I feel like a dunce. I just “assumed” there wasn’t a setting. It’s working perfectly now.

            I really hope this gets integrated into the plugin – you’ve done a great job (and helped me immensely).

          • Great – glad it’s working for you!

  2. Very cool Lee! I have been impatiently waiting for the xml sitemap plugin to get updated with this feature. I just installed you ready-to-go version and it appears to be working great.

    It took me a minute to get it running because I was a little thrown by the “you must have at least WordPress 2.9″ error. I was getting the error because my custom theme didn’t have the add_theme_support ‘post-thumbnail’ option in it’s function.php file.

    Could be worth updating it too say “must have 2.9+ and post-thumbnail theme support”.

    Thanks for putting this together!

  3. I’m glad I came accross your website while googling why google xml sitemap generator prevents images from my blog from being indexed. I saw your patch and thought it might have been a solution but then realised my blog doesn’t support post thumbnails (I’ve been using images uploaded to a nextgen gallery in most cases). Do you have any ideas on how to fix this bug? Google images has always been an important source of traffic for me and certainly not only for me. Do you have any ideas? I assume since you’ve written that patch to sitemap generator plugin, you do have enough knowledge to help =] Can’t wait for your response (I would most prefer if you sent me an email, I kindly ask for that :))

    • Hi Gabi,

      There’s no reason that Google XML Sitemap Generator would “Block” Google indexing your images. Even if the images weren’t in the file that doesn’t mean that Google can’t find them and identify them. I’ve had a look at your robots.txt file and that seems fine (That *can* block Google from indexing certain files on your site) – so I guess it’s just a Google thing …

      Best thing would be to sign up for a Google Webmaster Tools account and check it’s nt showing any problems for your site:

      http://www.google.com/webmasters/

  4. Hello Lee really thanks for this plugin, but How i Can see if it work? I have installed and checked the “thumb post” in xml sitemap plugin but I don’t know if it work, where i can see it?
    Thanks
    Simone

    • View the source of your sitemap in your web browser, and check for two things:
      xmlns:image=”http://www.google.com/schemas/sitemap-image/1.1″ in the urlset tag, and one or more tags…

  5. Hello Lee Thanks for your reply! I have see my sitemap.xml
    in the header I see

    but in the post / tag page / archive i didn’t see any tag for images
    Thanks ;)

    • Does your site actually use WordPress “post thumbnails”? How do you set the image for a blog post when you publish it?

  6. mmmm oh no.. I don’t use the built post thumbnails of wp 2.9 I use to make it the plugin Thumbnail for Excerpts..

    • That’s why then I’m afraid ….

      Unfortunately plugins like that, and older themes use a myriad of different ways of storing the “thumbnail” information – so there’s no nice generic way of detecting them and adding them …

      My best suggestion would be to use the patch, but to modify the code where it picks up the thumbnail image to match how your plugin stores it – but that’d be a custom solution for your site, and you’d have to maintain it ongoing …

  7. Hi, this sounds like what I need but maybe I am missing something. I have been using PS Auto Sitemap to create a page that is a sitemap, which I use for my homepage. I want to have a similar page that uses thumbnails next to each post or page listed. Can your ready-to-use version of this plugin do that? If so, how do I make the page appear on my site? I haven’t found any clue as to if and how that can be done. If it can’t, do you know of one that will? Or would you be interested in doctoring the PS Auto Sitemap plugin (or some other one) so it would have a thumbnail at the head of each entry it generates? Thanks.

    • Can your ready-to-use version of this plugin do that?

      Hi, there is no ready-made version, but even if there was, then no – the Google XML Sitemaps plugin doesn’t create an HTML version of the sitemap.

      If it can’t, do you know of one that will?

      Not off the top of my head – but I’d be surprised if there wasn’t a plugin to do it at wordpress.org …

  8. Great, plugin patch… I think you’re the first and the only one on the wordpress community. who made a patch on this Google XML Sitemap.. I’ve been looking for something like this because my theme is tumblog style and depends on featured image (post thumbnail) since my site is about gallery collections and other image sitemap generators can’t find my featured image to create a sitemap. So, thank you, for your contribution. I hope that you can get this plugin for downloads… Oh yeah, I just saw just the new update for Google XML sitemap and still this feature is not added, I wonder why… Anyway.. is there a way to incorporate this to the latest one? Again, big thanks..

Leave a Reply

Required fields are marked *.