• Resolved Dave Lavoie

    (@davelavoie)


    Hi there,

    I wanted to know if this plugin is going to use the new WP Sitemap feature, as detailed on this page: https://make.ww.wp.xz.cn/core/2020/07/22/new-xml-sitemaps-functionality-in-wordpress-5-5/

    The reason I’m asking this is because I’m dealing with a website that has tens of thousands of posts, so the TSF sitemap feature won’t work (it won’t generate the sitemap when I raise the limit above a certain point). However, the new WP Sitemap feature does work well… with the exception that it doesn’t exclude the post types I wanted to exclude, as set under the Exclusions tab of the General Settings of TSF plugin.

    It would be nice if TSF gave us the choice between the new WP Sitemap feature or the one bundled with the TSF. In the case where the native WP Sitemap is used, the plugin could still use the newly available hooks (wp_sitemaps_taxonomies and wp_sitemaps_post_types) to exclude post types and taxonomies from being generated by the native WP sitemap, based on TSF exclusions settings.

    So I just wanted to know if it was planned or not. 🙂

    Thanks for your work!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Dave Lavoie

    (@davelavoie)

    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
    Plugin Author Sybre Waaijer

    (@cybr)

    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 🙂

    Thread Starter Dave Lavoie

    (@davelavoie)

    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!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Native WP Sitemap integration’ is closed to new replies.