Skip Navigation

WPML Version: 3.2.2


Filters a WordPress permalink and converts it to a language-specific permalink based on the language URL format set in the WPML language settings.

This means that when “Language URL format” is set to “Different languages in directories” the permalink will be returned in the form. When “A different domain per language” is selected the permalink will be converted to include the correct domain assigned to the requested language.

Retrieving Localized Content
(string) (Required) The WordPress generated URL to filter.
(string) (Optional) The language to convert the url into. It accepts a 2-letter code. When set to null, it falls back to default language for root page, or current language in all other cases. Default is null
(boolean) (Optional) Enable full conversion of hard-coded URLs.
hook example usage:

Example 1

For example, if we have “Different languages in directories” selected, we can use the following code:

// will return
$wpml_permalink = apply_filters( 'wpml_permalink', '', 'de' );	

Example 2

We have a page and its translation Let’s say we are calling the filter while we are displaying the home page

// displays (wrong)
echo apply_filters( 'wpml_permalink', '', 'fr' ); 

// displays (correct)
echo apply_filters( 'wpml_permalink', '', 'fr', true ); 

Important notes about the second example:

  • The full resolution is a heavy process, so WPML has to persist the resolved URLs in the database. The first call to wpml_permalink should significantly increase the database queries and load time. But the subsequent calls should not overload the process.
  • The database persistence is partially cleared when post/terms are updated or deleted. And it’s fully cleared when visiting Settings -> Permalinks (this is a good troubleshooting option in case you encounter any issues).
  • In case the URL could not be resolved, the filter wpml_permalink will return the original URL.