This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Our next available supporter will start replying to tickets in about 1.74 hours from now. Thank you for your understanding.

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by bartU-2 5 months, 4 weeks ago.

Assigned support staff: Noman.

Author Posts
April 22, 2019 at 2:08 pm #3656247

bartU-2

Hi,

I have a theme, with different option fields, in which I can input text.

I need one field, to be able to contain two languages at the same time:

[wpml_language language=”en”]Free shipping [/wpml_language]
[wpml_language language=”nl”]Gratis verzending[/wpml_language]

I find it confusing, that we have to look in the gigantic haystack, to hope to find that one string and translate it.
It would be more user-friendly, just to add the languages in one field if I choose to.
With qTranslate such efficiënt conditional languages shortcodes are possible.

I tried this plugin, but it does not work :
https://wordpress.org/plugins/wpml-short-code-translator/

April 22, 2019 at 3:16 pm #3656641

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting WPML Support.

- You can achieve it using built in WPML shortcode and WPML String Translation plugin:

[wpml-string context="my-domain" name="my-name"]My string[/wpml-string]

Here is doc for more details:
https://wpml.org/documentation/support/wpml-coding-api/shortcodes/#wpml-string

OR

- You can achieve it using custom shortcode as follows:

1. Please add this function in your theme’s or child theme functions.php file

add_shortcode( 'wpml_language', 'wpml_language_func');
function wpml_language_func( $attr, $content = null ){
     
    extract(shortcode_atts(array(
 
        'language' => '',
 
    ), $attr));
     
    $current_language = ICL_LANGUAGE_CODE;
     
    if($current_language == $language){
        $output = do_shortcode($content);
    }
         
    return $output;
}

2. Then use below shortcodes in your post/pages where you want:

[wpml_language language="en"]Free shipping [/wpml_language]
[wpml_language language="nl"]Gratis verzending[/wpml_language]

I hope it helps,

Thank you

April 22, 2019 at 3:27 pm #3656665

bartU-2

Works like a charm Norman, you genius !
Thanks man 🙂