Skip to content

Instantly share code, notes, and snippets.

@dhirenpatel22
Created March 16, 2026 19:06
Show Gist options
  • Select an option

  • Save dhirenpatel22/e1a1f162e378db42d8497ef2ee10151e to your computer and use it in GitHub Desktop.

Select an option

Save dhirenpatel22/e1a1f162e378db42d8497ef2ee10151e to your computer and use it in GitHub Desktop.
Remove child category from Yoast SEO Sitemap.xml
<?php
// Remove child category from Sitemap.xml
add_filter( 'wpseo_sitemap_url', 'sitemap_exclude_taxonomy' );
function sitemap_exclude_taxonomy( $url = null, $type = null, $term = null ) {
$dataurl = $url;
$url = explode('brands/',$url);
$url_data = explode('/',$url[1]);
$term_slug = $url_data[0];
$texonomy = get_term_by('slug', $term_slug , "wsac_cse_make");
if(!$texonomy->parent)
{
return $dataurl;
}
}
add_filter('wpseo_sitemap_exclude_empty_terms', 'return_false');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment