Skip to content

Instantly share code, notes, and snippets.

@amboutwe
Last active July 29, 2018 13:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amboutwe/39ffabff64e400df2bad8d10a6c089bd to your computer and use it in GitHub Desktop.
Save amboutwe/39ffabff64e400df2bad8d10a6c089bd to your computer and use it in GitHub Desktop.
Sitemaps: There are two sets of code in this gist, one for a single taxonomy or for multiple taxonomies. Only copy the section you need and replace the taxonomy_slug with the actual name of the taxonomy slug to be excluded.
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Exclude One Taxonomy From Yoast SEO Sitemap
* Credit: Yoast KB https://kb.yoast.com/kb/how-to-customize-the-sitemap-index/
* Last Tested: Apr 05 2018 using Yoast SEO 7.2 on WordPress 4.9.5
*********
* Please note that changes will be applied upon next sitemap update.
* To manually refresh the sitemap, please disable and enable the sitemaps.
*/
add_filter( 'wpseo_sitemap_exclude_taxonomy', 'sitemap_exclude_taxonomy', 10, 2 );
function sitemap_exclude_taxonomy( $value, $taxonomy ) {
if ( $taxonomy == 'taxonomy_slug' ) return true;
}
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Exclude Multiple Taxonomies From Yoast SEO Sitemap
* Credit: Yoast KB https://kb.yoast.com/kb/how-to-customize-the-sitemap-index/
* Last Tested: Apr 05 2018 using Yoast SEO 7.2 on WordPress 4.9.5
*********
* Please note that changes will be applied upon next sitemap update.
* To manually refresh the sitemap, please disable and enable the sitemaps.
*/
add_filter( 'wpseo_sitemap_exclude_taxonomy', 'sitemap_exclude_taxonomy', 10, 2 );
function sitemap_exclude_taxonomy( $value, $taxonomy ) {
$taxonomy_to_exclude = array('taxonomy_slug1','taxonomy_slug2', 'taxonomy_slug3');
if( in_array( $taxonomy, $taxonomy_to_exclude ) ) return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment