# Show a Custom Field From the Right WPML Translation

> Adds a [wpide_wpml_field] shortcode that displays a custom field from the current-language version of any post or page, so one shortcode works in every language.

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

## Code

```php
add_shortcode( 'wpide_wpml_field', function ( $atts ) {
    $atts = shortcode_atts( array( 'key' => '', 'id' => 0 ), $atts, 'wpide_wpml_field' );
    $key  = sanitize_key( $atts['key'] );
    $id   = $atts['id'] ? absint( $atts['id'] ) : get_the_ID();

    if ( '' === $key || ! $id || is_protected_meta( $key, 'post' ) ) {
        return '';
    }

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

    $value = get_post_meta( $id, $key, true );

    return is_scalar( $value ) ? wp_kses_post( (string) $value ) : '';
} );
```

## Notes

Use [wpide_wpml_field key="opening_hours" id="42"]; leave out id to use the current post. Falls back to the original post when no translation exists.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Show a Custom Field From the Right WPML Translation" 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/
