$converted_url = apply_filters( 'wpml_site_url_in_language', string $url, string $language_code, string $source_language_code = null );
Description
Converts a URL of this site into the same address in another language, as the wpml_permalink filter does with full resolution. Use it for URLs that you did not build yourself, for example a link that a user typed in a form or a custom field.
The filter converts the URL only when it is a page address of this site:
- The URL starts with
http://orhttps://. - Its host is the host of the site, or a domain of a language when “A different domain per language” is selected.
- Its path is inside the path of the site home URL.
- It does not point to a file, for example
.pdfor.jpg. - It is not inside
wp-content,wp-includesorwp-admin. - The
wpml_should_resolve_single_urlfilter does not returnfalsefor it.
A URL of a post, a page or a term becomes the URL of its translation. A URL with no post or term behind it, like the home URL or a date archive, gets the language URL format of the site. The filter keeps the query string and the fragment.
The filter returns every other value as it is: external URLs, relative URLs, mailto: and tel: links, anchors like #top, and values that are not a string.
Arguments
$urlstringRequiredThe URL to convert, for example a URL that a user typed in a field.$language_codestringRequiredThe language to convert the URL into, for examplefr.$source_language_codestringOptionalThe language of the content that holds the URL. WPML passes it to thewpml_should_resolve_single_urlfilter. Default isnull.
Example Usage
Example
With “Different languages in directories” selected:
// returns http://example.org/fr/contact/ (the translation of the page) $url = apply_filters( 'wpml_site_url_in_language', 'http://example.org/contact/', 'fr' ); // returns http://example.org/fr/2026/05/ (a date archive, with no post behind it) $url = apply_filters( 'wpml_site_url_in_language', 'http://example.org/2026/05/', 'fr' ); // returns the URL as it is (a file) $url = apply_filters( 'wpml_site_url_in_language', 'http://example.org/wp-content/uploads/menu.pdf', 'fr' ); // returns the URL as it is (another site) $url = apply_filters( 'wpml_site_url_in_language', 'https://wordpress.org/', 'fr' );