Contents
Overview #
All WordPress.com sites come with XML and News sitemaps built-in. The sitemaps are automatically generated, cached for a 24-hour period, and updated whenever a post is published, updated, or deleted. Learn more about the sitemaps here: http://en.support.wordpress.com/sitemaps/
You can customize some of the output by hooking into various filters. A non-exhaustive list of examples is below. If you’re interested in modifying something beyond what’s shown below, just let us know.
For local testing, you can use the following code, which is a stripped-down version of the sitemap generator we have on WordPress.com: https://gist.github.com/7374b43a477d0eab26b4
XML Sitemap: Exclude certain posts #
add_filter( 'sitemap_skip_post', 'x_sitemap_skip_post', 10, 2 );
function x_sitemap_skip_post( $skip, $post ) { // $post is an object with properties: ID, post_type, post_modified_gmt, comment_count
if ( get_post_meta( $post->ID, 'x_skip_post', true ) )
$skip = true;
return $skip;
}
XML Sitemap: Include additional post types #
By default, sitemaps only include posts. Use the following to include additional post types.
add_filter( 'wpcom_sitemap_post_types', 'x_sitemap_add_gallery_post_type' );
function x_sitemap_add_gallery_post_type( $post_types ) {
$post_types[] = 'gallery';
return $post_types;
}
News Sitemap: Change the publication name #
add_filter( 'wpcom_sitemap_news_sitemap_item', 'x_filter_news_sitemap_name', 10, 2 );
function x_filter_news_sitemap_name( $item, $post ) {
$item['n:news']['n:publication']['n:name'] = 'My Publication'; // modify as needed for your site
return $item;
}