This page will clean up sitemap settings to exclude problematic parameter URLs.
\’page\’,\n \’post_status\’ => \’publish\’,\n \’meta_query\’ => array(\n array(\n \’key\’ => \’_wp_page_template\’,\n \’value\’ => \’utility\’,\n \’compare\’ => \’LIKE\’\n )\n ),\n \’fields\’ => \’ids\’\n ));\n \n // Exclude installer and utility pages\n $utility_slugs = array(\n \’redirect-rule-installer\’,\n \’robots-txt-updater\’,\n \’sitemap-cleanup-tool\’,\n \’meta-fix-activator\’,\n \’final-meta-installer\’,\n \’woocommerce-meta-fix\’,\n \’updated-final-meta-installer\’\n );\n \n foreach ($utility_slugs as $slug) {\n $page = get_page_by_path($slug);\n if ($page) {\n $excluded[] = $page->ID;\n }\n }\n }\n \n return $excluded;\n}\n\n// Hook into sitemap exclusion\nadd_filter(\’wp_sitemaps_posts_query_args\’, function($args, $post_type) {\n if ($post_type === \’page\’) {\n $excluded = exclude_utility_pages_from_sitemap(array(), $post_type);\n if (!empty($excluded)) {\n $args[\’post__not_in\’] = $excluded;\n }\n }\n return $args;\n}, 10, 2);\n\n// Hook into Rank Math sitemap exclusion\nadd_filter(\’rank_math/sitemap/exclude_post\’, function($exclude, $post) {\n $excluded_ids = exclude_utility_pages_from_sitemap(array(), $post->post_type);\n return in_array($post->ID, $excluded_ids) ? true : $exclude;\n}, 10, 2);\n?>’;
// Write the plugin file
$result = file_put_contents($mu_plugin_dir . ‘sitemap-cleanup.php’, $plugin_content);
if ($result !== false) {
echo ‘
‘;
echo ‘
The plugin will now exclude from sitemaps:
‘;
echo ‘
- ‘;
- URLs with AMP parameters (?amp=1, &=1)
- URLs with noamp parameters (?noamp=mobile, &noamp=mobile)
- Product copy URLs (/product/*-copy/)
- Old shop URLs that redirect incorrectly
- Utility pages (installers, fixers, etc.)
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
This will clean up your sitemap and help Google focus on the correct URLs.
‘;
} else {
echo ‘
‘;
}
}
else {
echo ‘
‘;
echo ‘
This will exclude problematic URLs from your sitemap:
‘;
echo ‘
- ‘;
- Parameter-based URLs (AMP, noamp)
- Duplicate product URLs
- Old shop URLs that cause redirects
- Utility pages created for fixes
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
‘;
echo ‘
This helps Google focus on crawling only the correct, canonical URLs.
‘;
}
?>