Skip Navigation

WPML Version: 3.2


Returns a post type link or taxonomy term link in the current language.

* Note: There are alternative ways to retrieve an element’s link which gives developers fuller control over the HTML output.
WordPress offers a number of functions to do this such as get_permalink(), get_term_link(), etc.

If you plan on using functions that require a post type or term ID as a parameter then you may be interested in looking into the wpml_object_id filter.

Retrieving Localized Content
apply_filters( 'wpml_element_link', int $element_id, string $element_type, string $link_text, array $optional_parameters, string $anchor, bool $echo, bool $return_original_if_missing )
(int) (Required) The ID of the post type (post, page, attachment, custom post) or taxonomy term (tag, category, custom taxonomy) to link to
(string) (Optional) The type of element to link to. Can be ‘post’, ‘page’, ‘attachment’, ‘{custom post}’, ‘tag’, ‘category’, ‘{custom taxonomy}’. Defaults to ‘post’
(string) (Optional) The link text. Defaults to the element’s name
(array) (Optional) Arguments for the link
(string) (Optional) Anchor for the link
(bool) (Optional) 0|false to return or 1|true to echo the localized link. Defaults to true
(bool) (Optional) If set to true it will always return a value (the original value, if translation is missing). Default is TRUE
hook example usage:


//produces: <a href="/hello-world/">Hello World!</a>
apply_filters( 'wpml_element_link', 1 );

//produces: <a href="/sample-page/">Custom link text for the sample page</a>
apply_filters( 'wpml_element_link', 2, 'page', __( 'Custom link text for the sample page' ) );

//produces: <a href="/sample-page/?category=foo&bar=baz">Sample Page</a>
apply_filters( 'wpml_element_link', 2, 'page', '', array( 'category'=>'foo', 'bar'=>'baz' ) );

//produces: <a href="/sample-page/#contact">Sample Page</a>
apply_filters( 'wpml_element_link', 2, 'page', '', '', 'contact' );

//produces: <a href="/category/uncategorized/">Uncategorized</a>
apply_filters( 'wpml_element_link', 1, 'category' );

//produces: <a href="/?attachment_id=25">'Attachment image title</a>
apply_filters( 'wpml_element_link', 25, 'attachment', __( 'Attachment image title' ) );