How to Add Custom Post Types to wp-sitemap.xml
The wp-sitemap.xml file that was added to WordPress back in is super handy.
I use it in my plugin, Click SEO, which is probably the simplest SEO plugin you’ll ever use.
Say you want to programmatically add a WordPress custom post type to your WP Sitemap, though. Here’s how you can do that (by adding this to your functions.php file):
// add a custom post type with the slug 'events' to wp-sitemap.xml
add_filter( 'wp_sitemaps_post_types', 'clicknathan_add_post_type_to_sitemap' );
function clicknathan_add_post_type_to_sitemap( $post_types ){
$post_types[] = 'event';
return $post_types;
}
In the example above, we add a post type with the slug event.
There you have it, append /wp-sitemap.xml to your WordPress homepage’s URL and you’ll see the following.

Up Next: How to Properly Use, and Self-Host, Variable Web Fonts