Exclude terms from the XML Sitemap

Need help with this?
Purchase All in One SEO Pack Pro to get dedicated support from us.

Buy Now

The filter below can be used to exclude terms (categories, tags, etc) from the XML Sitemap.

NOTE: This only excludes the terms themselves, not the posts assigned to the terms.  For example, if you exclude the Uncategorized category, only that category will be excluded, not the posts in that category.

function custom_sitemap_taxonomy_terms_args( $args ) {
     // Exclude individual terms by id.
     $args['exclude'] = '1,2,3';

     // Exclude terms, including child terms.
     $args['exclude_tree'] = '1,2,3';

     return $args;
}
add_filter( 'aioseop_sitemap_add_post_types_taxonomy_terms_args', 'custom_sitemap_taxonomy_terms_args' );

add_filter( 'aioseop_sitemap_exclude_tax_terms', 'custom_sitemap_taxonomy_terms_args' );

Note that $args[‘exclude_tree’] is used to exclude the parent category and all sub-categories.

For instructions on how to use this code, please refer to our FAQ here.

  • Was this helpful ?
  • YesNo