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 ‘

SUCCESS: Sitemap Cleanup plugin installed successfully!

‘;
echo ‘

The plugin will now exclude from sitemaps:

‘;
echo ‘

    ‘;
    echo ‘

  • URLs with AMP parameters (?amp=1, &amp=1)
  • ‘;
    echo ‘

  • URLs with noamp parameters (?noamp=mobile, &noamp=mobile)
  • ‘;
    echo ‘

  • Product copy URLs (/product/*-copy/)
  • ‘;
    echo ‘

  • Old shop URLs that redirect incorrectly
  • ‘;
    echo ‘

  • Utility pages (installers, fixers, etc.)
  • ‘;
    echo ‘

‘;
echo ‘

This will clean up your sitemap and help Google focus on the correct URLs.

‘;
} else {
echo ‘

ERROR: Could not create plugin file.

‘;
}
}
else {
echo ‘

Clean Up Sitemap

‘;
echo ‘

This will exclude problematic URLs from your sitemap:

‘;
echo ‘

    ‘;
    echo ‘

  • Parameter-based URLs (AMP, noamp)
  • ‘;
    echo ‘

  • Duplicate product URLs
  • ‘;
    echo ‘

  • Old shop URLs that cause redirects
  • ‘;
    echo ‘

  • Utility pages created for fixes
  • ‘;
    echo ‘

‘;
echo ‘

This helps Google focus on crawling only the correct, canonical URLs.

‘;
}
?>