WPML
SignaturePHP
$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:// or https://.
  • 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 .pdf or .jpg.
  • It is not inside wp-content, wp-includes or wp-admin.
  • The wpml_should_resolve_single_url filter does not return false for 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

  • $urlstringRequired

    The URL to convert, for example a URL that a user typed in a field.
  • $language_codestringRequired

    The language to convert the URL into, for example fr.
  • $source_language_codestringOptional

    The language of the content that holds the URL. WPML passes it to the wpml_should_resolve_single_url filter. Default is null.

Example Usage

Example

With “Different languages in directories” selected:

PHP
// 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' );