# Link to the Current-Language Version of Any Page

> Adds a [wpide_wpml_link id="123"] shortcode that links to the translation of a page in the language being viewed, using that translation's title, so internal links never send visitors to the wrong language.

- Type: PHP
- Runs: Run everywhere
- Category: [Multilingual](https://wpide.com/library/category/multilingual/)
- Tags: wpml, links, shortcode
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/wpml-translation-link-shortcode/

## Code

```php
add_shortcode( 'wpide_wpml_link', function ( $atts ) {
    $atts = shortcode_atts( array( 'id' => 0, 'text' => '' ), $atts, 'wpide_wpml_link' );
    $id   = absint( $atts['id'] );

    if ( ! $id || ! get_post( $id ) ) {
        return '';
    }

    if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
        $id = (int) apply_filters( 'wpml_object_id', $id, get_post_type( $id ), true );
    }

    if ( 'publish' !== get_post_status( $id ) ) {
        return '';
    }

    return sprintf( '<a href="%1$s">%2$s</a>', esc_url( get_permalink( $id ) ), esc_html( '' !== $atts['text'] ? $atts['text'] : get_the_title( $id ) ) );
} );
```

## Notes

Add text="..." to set your own link text (it can be translated with the page). Falls back to the original page if there is no translation.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Link to the Current-Language Version of Any Page" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
