Many website owners choose to manage multilingual websites using separate instances, allowing for the unique use of design and functionality catered to each language; however a common challenge arises when certain tools, such as usercentrics, lack the option to specify separate Sitemaps within the same project (Domain).
In response to this challenge, I’ve implemented a PHP tweak, check out the code and use it inside Child Theme’s functions.php, and the add a new file ‘custom-sitemap.php’ on same directory
function.php part:
include_once ‘custom-sitemap.php’;
add_filter(‘rank_math/sitemap/providers’, function($external_providers) {
$external_providers[‘custom’] = new \RankMath\Sitemap\Providers\Custom();
return $external_providers;
});// Exclude RankMath’s sitemap from server-side caching
add_filter(‘rank_math/sitemap/enable_caching’, ‘__return_false’);
The custom-sitemap.php part:
<?php
namespace RankMath\Sitemap\Providers;defined(‘ABSPATH’) || exit;
class Custom implements Provider {
public function handles_type($type) {
return ‘custom’ === $type;
}// Custom sitemap links
public function get_index_links($max_entries) {return [
// English version of the sitemap
[
‘loc’ => \RankMath\Sitemap\Router::get_base_url(‘en/sitemap_index.xml’),
‘lastmod’ => ”,
],
];
}// Custom page links
public function get_sitemap_links($type, $max_entries, $current_page) {
$links = [];
return $links;
}}
Feel free to use this code for your need.