Documentation > Developers > Extracting translated URLs

Extracting translated URLs

Browse Docs
Search Documentation

The following code example generates translated URLs in all active languages starting with the absolute path to a default language URL.

// list of urls in default language for which you need the equivalent in all languages
$product_feed_url_list_in_default_language = [ 'http://example.com/product1', 'http://example.com/product2' ];
$trp = TRP_Translate_Press::get_trp_instance();
$trp_settings = $trp->get_component( 'settings' );
$settings = $trp_settings->get_settings();
$url_converter = $trp->get_component( 'url_converter' );
$translated_urls = [];
foreach ( $product_feed_url_list_in_default_language as $url ) {
// iterating over active TranslatePress languages
foreach ( $settings['publish-languages'] as $language ) {
if ( $settings['default-language'] === $language ) {
// skip default language
continue;
}
// generate translated url for a particular language
$translated_urls[] = esc_url( $url_converter->get_url_for_language( $language, $url, '' ) );
}
}

TranslatePress Multilingual

The best website localization service for WordPress websites. Manage everything from a visual interface.