Get up and Running logo
We do geek so you don't have to
Browse: Home / 2010 / June / Adding Custom Content Types to the Sitemap

Adding Custom Content Types to the Sitemap

By Mark on June 29, 2010

I was working on a customer site and realised that the Google Sitemap Generator I use wasn’t including the Custom Content Types I had created in WordPress 3.0.

Luckily the original plugin writer (Arne Brachhold) had created a hook to enable the addition of extra pages. Since I couldn’t wait for Arne to catch up, I created this plugin plugin.

The plugin has no additional admin, and will automatically add all your new public custom content types to the sitemap. If you wish to filter out some particular content types you can filter them out using add_filter which you add to the functions.php file in your theme directory:

function my_filter($posttypes)
{
    // to remove posttypes of a particular name
    foreach($posttypes as $key => $val)
    {
        if($val=='super_duper')
        {
            unset($posttypes[$key]);
        }
    }
 
    // to add posttypes e.g. page
    $posttypes[] = 'page';
 
    return $posttypes;
}
 
add_filter('guar_sitemap_posttype_filter','my_filter',10,1);

Note: This doesn’t fix the outstanding Multi-site issue – though I believe Arne is on the case.

Update (1.1): Excluded PostIDs and Categories are now honoured. The download reflects these changes.

Update (1.2): Uses the default Change Frequency for Posts.

Download Plugin: guar_sitemap_1.2

Posted in Search Engine Optimisation, Web Development | Tagged Custom Content Types, Filter, Sitemaps, WordPress 3.0 | 65 Responses

Logging In...

Profile cancel

Sign in with Twitter Sign in with Facebook
or

Not published

  • 65 Replies
  • 63 Comments
  • 0 Tweets
  • 0 Facebook
  • 2 Pingbacks
Last reply was 4 months ago
  1. jeff
    View July 7, 2011

    Hey – thanks so much for this fix! I know the original Google XML Sitemaps now has support for Custom Post Types in the beta version, but my client needed this now.

    Very cool of you to write and release this. Muchas Gracias, Amigo mio!

  2. OrT
    View July 16, 2011

    Still working like a charm, thanks a lot!

  3. Bora
    View September 9, 2011

    thanks! worked like a charm :)

  4. serge
    View September 26, 2011

    Hi,

    thanks for the code, you might be also interested in a function like this to exclude private post types automatically

    ( note gode is not tested yet) :

    function custom_exclude_non_public($post_types) {
    	$custom_post_types = get_post_types(array(
    		'_builtin' => false
    		),
    		'objects',
    		'and'
    	);
    	$keys = array_flip($post_types);
    	if(!is_null($keys)) {
    		foreach($custom_post_types as $custom_post_type) {
    			if($custom_post_type->publicly_queryable === false || $custom_post_type->exclude_from_search === true) {
    				$key = $keys[$custom_post_type->name];
    				unset($post_types[$key]);
    			}
    		}
    	}
    }
    add_filter('guar_sitemap_posttype_filter','custom_exclude_non_public',50,1);
    
  5. Mark
    View September 26, 2011

    @serge, thanks for that, that’s what the filter is for.

  6. Matt Smith, modMACRO
    View November 7, 2011

    Doesn’t appear to work with WordPress 3.2.1 and XML Sitemap Generator 3.2.6 – Same results as without your plugin activated.

    Any thoughts?

  7. Mark
    View November 8, 2011

    Hi Matt, just tested WP 3.2.1 and the generator 3.2.6 and it works fine. You may need to run a manual sitemap generation from the admin panel for the first time – when you create a new post, this should update automatically.

  8. serge
    View November 18, 2011

    Hi, just tested the code here http://thesistut.com/

    it was buggy, here is the fixed version :

    function custom_exclude_non_public($post_types = array()) {
    	$custom_post_types = get_post_types(array(
    		'_builtin' => false
    		),
    		'objects',
    		'and'
    	);
    	$keys = array_flip($post_types);
    	if(!is_null($keys)) {
    		foreach($custom_post_types as $custom_post_type) {
    			if($custom_post_type->publicly_queryable === false || $custom_post_type->exclude_from_search === true) {
    				$key = $keys[$custom_post_type->name];
    				unset($post_types[$key]);
    			}
    		}
    	}
    	return $post_types;
    }
    add_filter('guar_sitemap_posttype_filter','custom_exclude_non_public',50,1);
    
  9. serge
    View November 18, 2011

    I have a question is there any way to apply same priority to custom post types as to posts?

  10. serge
    View November 18, 2011

    sorry, found that in the code

  11. Mark
    View November 18, 2011

    Self-help is marvelous! Thanks for the little update on your filter.

  12. Aviss
    View March 2, 2012

    thank you very much :)

  13. FanaticWeb
    View March 10, 2012

    Hi everyone, I’m new to this XML site map business but starting to see its benefits, was wondering about the custom post tags? I can see the custom posts in my xml file but not the custom post tags. Any idea if this is normal or simply not implemented yet in the plugin?

    Cheers!

  14. Majid Ahmad Sultani
    View 7 months ago

    i have installed your given plugin after installed i regenerate sitemap nanualy and i havent see any changing it not generate full sitemap of site please help me

  15. Ameri Ichinose
    View 4 months ago

    Hi Matt, just tested WP 3.2.1 and the generator 3.2.6 and it works fine. You may need to run a manual sitemap generation from the admin panel for the first time – when you create a new post, this should update automatically.

Comment navigation

← Older Comments
« Previous Next »
  • Welcome
  • Experience
    • Development
    • SEO
    • Training
  • Portfolio
  • Blog
  • Contact

Keep in Touch

   Skype Me™!

Recent Tweets

Follow Me on Twitter

Recent Comments

  • Ameri Ichinose on Adding Custom Content Types to the Sitemap
  • Majid Ahmad Sultani on Adding Custom Content Types to the Sitemap
  • FanaticWeb on Adding Custom Content Types to the Sitemap
  • Aviss on Adding Custom Content Types to the Sitemap
  • Mark on Adding Custom Content Types to the Sitemap

Tags

Advertising automatic search engine submission Business Ceremony Designer Classes competitive edge content management system Content management systems Costs CSS cufon Custom Content Types customer service Debugging Digital typography E-mail Faceted search Filter Font font detection fonts Google IDM Property Services Internet marketing Katie Deverell keywords linguistic technology Marketing multisite online marketing Posterous Search engine optimization search results seo Sitemaps Small business social media Taxonomy The Climate Run Theme Development Typesetting Usability Web typography WordPress WordPress 3.0

Copyright © 2013 Get up and Running.