By the way, in case no such integration was planned, for anyone who would like to use TSF settings to disable taxonomies and post types for the native WP Sitemap feature, you can add the following in the functions.php file of your theme:
/**
* Filters the list of post object sub types available within the sitemap.
*
* @hook wp_sitemaps_post_types
* @author [email protected]
*
* @param WP_Post_Type[] $post_types Array of registered post type objects keyed by their name.
* @return array $post_types Filtered array of registeed post types minus those disabled in The SEO Framework plugin.
*/
function exclude_post_types_from_wp_sitemap( $post_types ) {
$tsf_options = get_option( 'autodescription-site-settings' );
if ( ! empty( $tsf_options['disabled_post_types'] ) ) {
foreach ( $tsf_options['disabled_post_types'] as $post_type_slug => $value ) {
unset( $post_types[ $post_type_slug ] );
}
}
return $post_types;
}
add_filter( 'wp_sitemaps_post_types', 'exclude_post_types_from_wp_sitemap' );
/**
* Filters the list of taxonomy object subtypes available within the sitemap.
*
* @hook wp_sitemaps_taxonomies
* @author [email protected]
*
* @param WP_Taxonomy[] $taxonomies Array of registered taxonomy objects keyed by their name.
* @return array $taxonomies Filtered array of registeed taxonomies minus those disabled in The SEO Framework plugin.
*/
function exclude_taxonomies_from_wp_sitemap( $taxonomies ) {
$tsf_options = get_option( 'autodescription-site-settings' );
if ( ! empty( $tsf_options['disabled_post_types'] ) ) {
foreach ( $tsf_options['disabled_post_types'] as $post_type_slug => $value ) {
$disabled_taxonomies = get_object_taxonomies( $post_type_slug );
if ( ! empty( $disabled_taxonomies ) ) {
foreach ( $disabled_taxonomies as $taxonomy_slug ) {
unset( $taxonomies[ $taxonomy_slug ] );
}
}
}
}
return $taxonomies;
}
add_filter( 'wp_sitemaps_taxonomies', 'exclude_taxonomies_from_wp_sitemap' );
-
This reply was modified 5 years, 8 months ago by
Dave Lavoie. Reason: Formatting
Hi Dave!
I exclaimed in the v4.1 changelog that this feature will come. But, since Core Sitemaps was announced unexpectedly without a due notice (much like the Block Editor was), I couldn’t find the time to integrate it, and had to rush the major release ultimately.
In the changelog, I also briefly explained why not all sites should opt for the Core Sitemaps, and most will see better results using TSF’s sitemap–even though they might have thousands of posts. Results may vary for you, of course.
In any case, I recommend using this API method to test for the post’s indexing state for the Core Sitemaps:
// Example, non-functional code! You'll have to fill in the variables...
$indexable = the_seo_framework()->is_robots_meta_noindex_set_by_args(
[
'id' => $term_id ?? $post_id, // either term or post ID.
'taxonomy' => $taxonomy ?? '', // string for term query, empty string for post query
],
The_SEO_Framework\ROBOTS_IGNORE_PROTECTION
);
I don’t have an ETA for a proper integration with Core Sitemaps yet. But, I hope I can make it happen before the end of this year 🙂
Thanks @cybr, I totally forgot to consider to exclude from the core sitemap the posts that were marked as noindex by TSF. I’ll need to adapt my script to consider the post individual settings too!
I know there are good reasons to continue using TSF sitemap, that’s why I think an option allowing to select the type of sitemap (core or TSF) would be better than simply relying on the core sitemap. Of course, it means more work, but at least, with the hooks provided by WP to customize the sitemap, it’s possible.
Thanks for your reply!