Disable Sitemap Creation in WordPress SEO

This is a guest post by Ronald Huereca (@ronalfy):

By default, WordPress SEO will create XML sitemaps for custom post types with the public setting set to false. In my opinion, this is incorrect behavior. Here is a code snippet to disable sitemap creation for all non-public post types:

add_filter( 'wpseo_sitemap_exclude_post_type', 'exclude_sitemaps_yoast', 11, 2 );

function exclude_sitemaps_yoast( $exclude = false, $post_type ) {
	$post_type_object = get_post_type_object( $post_type );

	if ( $post_type_object->public === false )
		return true;

	return $exclude;
}

Leave a Reply