-
Situation:
i have a website for .de, .at and .ch. I dont use a multilanguage plugin because the content is the same. Everything works fine, all hreflang tags are set, the canonical, too.The post_sitemap.xml shows data like:
<?xml version=”1.0″ encoding=”UTF-8″?>
<?xml-stylesheet type=”text/xsl” href=”//www.URL.at/test/main-sitemap.xsl”?>
<urlset xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:image=”http://www.google.com/schemas/sitemap-image/1.1″ xsi:schemaLocation=”http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd” xmlns=”http://www.sitemaps.org/schemas/sitemap/0.9″>
<url>
<loc>https://www.URL.at/test/category/article1/</loc>
<lastmod>2024-09-30T12:32:21+00:00</lastmod>
</url>
<url>
<loc>https://www.URL.at/test/category/article2/</loc>
<lastmod>2024-09-26T12:11:09+00:00</lastmod>
</url>…
I want to add the alternate urls like:
<url>
<loc>https://www.URL.at/test/category/article1/</loc>
<xhtml:link rel=”alternate” hreflang=”de-at” href=”https://www.URL.at/test/category/article1/” />
<xhtml:link rel=”alternate” hreflang=”de-de” href=”https://www.URL.de/test/category/article1/” />
<xhtml:link rel=”alternate” hreflang=”de-ch” href=”https://www.URL.ch/test/category/article1/” />
<lastmod>2024-09-30T12:32:21+00:00</lastmod>
</url>…
with no result at all. Nothing happens here!
I use the following code:
function add_alternate_urls_to_sitemap( $url, $type, $object ) {
$base_urls = [
‘de’ => ‘https://www.URL.de’,
‘at’ => ‘https://www.URL.at’,
‘ch’ => ‘https://www.URL.ch’,
];foreach ( $base_urls as $lang => $base_url ) {
$alternate_link = [
‘rel’ => ‘alternate’,
‘hreflang’ => ‘de-‘.$lang,
‘href’ => $base_url . $_SERVER[‘REQUEST_URI’],
];if ( isset( $url[‘alternate’] ) && is_array( $url[‘alternate’] ) ) {
$url[‘alternate’][] = $alternate_link;
} else {
$url[‘alternate’] = [ $alternate_link ];
}
}
return $url;
}
add_filter( ‘rank_math/sitemap/entry’, ‘add_alternate_urls_to_sitemap’, 10, 3 );So where is the mistake i make?
The ticket ‘rank_math/sitemap/entry is not doing anything’ is closed to new replies.