Webdesing Regensburg

PHP Tweak for Multilingual WordPress Instances Sitemap with RankMath SEO

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:

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.

Follow us on social media

Need a hand with your project? Let us help you!

Our extensive experience in optimizing various tools and commitment to providing excellent assistance ensures top-notch solutions for our clients, making us their go-to partner for all their project needs.