By default the Sitemap module of the Jetpack plugin for WordPress does not include custom post types in its generated sitemap.xml.
I’m going to demonstrate some methods for adding this functionality to your WordPress website:
Method 1 – Add to an existing array
This site uses a custom portfolio post-type that is created in the theme’s functions.php, this is how it looks:
//* Create portfolio custom post type add_action( 'init', 'bayareawebs_portfolio_post_type' ); function bayareawebs_portfolio_post_type() { register_post_type( 'portfolio', array( 'labels' => array( 'name' => __( 'Portfolio', 'bayareawebs' ), 'singular_name' => __( 'Portfolio', 'bayareawebs' ), ), 'has_archive' => true, 'hierarchical' => true, 'menu_icon' => get_stylesheet_directory_uri() . '/lib/icons/portfolio.png', 'public' => true, 'rewrite' => array( 'slug' => 'portfolio', 'with_front' => false ), 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings' ), 'taxonomies' => array( 'portfolio-type' ), ) ); }
On line 16 simply add ‘jetpack_sitemap_post_types’, the end result will look like this
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings', 'jetpack_sitemap_post_types'
Method 2 – Add Filter in Functions.php
This method is a bit more dirty than the last, it is copied from this page in the WordPress forums. Simply copy and paste this into your functions.php and replace your_post_type with the the post type you want to add.
function jeherve_add_cpt_sitemaps( $post_types ) { $post_types[] = 'your_post_type'; return $post_types; } add_filter( 'jetpack_sitemap_post_types', 'jeherve_add_cpt_sitemaps' );
Method 3 – Edit the Jetpack Plugin
This isn’t a very good method as a plugin update will overwrite it. You can head to /wp-content/plugins/jetpack/modules/sitemaps/sitemap.php and on line 268 add an extra post type, it would look something like this:
$post_types = apply_filters( 'jetpack_sitemap_post_types', array( 'post', 'page', 'portfolio' ) );
Last Step
Publish and delete a post or page, that will run a cron job to generate a new sitemap.
khuong
all method Not work
Alex
It is working on this site, among others, using first method. Jetpack is outputting the following sitemap: https://www.legitwebs.com/sitemap.xml