Home / Admin / Add Translated Version Sitemap Entries for a Specific Post
Duplicate Snippet

Embed Snippet on Your Site

Add Translated Version Sitemap Entries for a Specific Post

This filter can be used to add Translated Version Sitemap Entries for a Specific Post.

You can replace "10" in "10 === $postId" with the ID of the desired post whose translated versions are being added. You can also replace en_US, en_CA, and en_UK with the desired language codes and the "location" values with the translated URLs.

10+
Code Preview
php
<?php
add_filter( "aioseo_sitemap_post", "aioseo_filter_sitemap_post", 10, 2 );
function aioseo_filter_sitemap_post( $entry, $postId ) {
	if ( 10 === $postId ) {
		// Set the language code for the main URL.
        $entry['language']  = 'en_US'
		// Add the translated versions (language code + URL).
		$entry['languages'] = [
			[
				'language' => 'en_CA'
				'location' => 'https://example.com/ca/page
			],
			[
				'language' => 'en_UK'
				'location' => 'https://example.com/uk/page
			]
		];
	}
	return $entry;
}

Comments

Add a Comment