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

Embed Snippet on Your Site

Add Translated Version Sitemap Entries for a Specific Term

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

You can replace "12" in "12 === $termId" 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_term", "aioseo_filter_sitemap_term", 10, 2 );
function aioseo_filter_sitemap_term( $entry, $termId ) {
	if ( 12 === $termId) {
		// 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