We can exclude content type, or individual node from XML Sitemap. But, is there anyway to exclude nodes with specific taxonomy term? For example excluding nodes with longlivethetroll
tag.
1 Answer
You can use hook_xmlsitemap_element_alter() to check if the node has a particular taxonomy term & exclude it.
function MYMODULE_xmlsitemap_element_alter(&$element, $link, $sitemap) {
// Check if link is a node link
if ($link['type'] == 'node') {
$node = node_load($link['id']);
// Code to check if $node has taxonomy term goes here
if ($node has taxonomy term) {
$element['disabled'] = TRUE; // This removes the node link from sitemap
}
}
}