• 0

WPML Conditional Statement in Global Scope


Question

Posted · Report post

Website URL: barreralawfirm.com/beta/
Framework Version: Just updated today. 
WordPress Version: Most recent
Plugins in Use: WPML,  Formcraft, Jetpack, SEO Ultimate
Server/Host: Siteground
Screenshots:
Details: Below

 

I am currently developing a website with both English and Spanish text. Dependent on the language selected via the fixed nav, the site will pull different code/text. Is there a way to run php in a textbox within the header or global scope? There is one section that needs to conform to that. I have checked the string translations and it isn't showing up to be manageable through that. I have also tried a <?php if(ICL_LANGUAGE_CODE=='en'): ?> statement to get it to switch manually but the code won't run.

 

Is there a better way to get this content to translate when on a different language?

 

Any help would be greatly appreciated.

 

 

Share this post


Link to post
Share on other sites

4 answers to this question

  • 0

Posted (edited) · Report post

Eventually got it to work with the following:

 

Created the shortcode in functions.php:

 

function webtreats_lang_test( $atts, $content = null ) {
    extract(shortcode_atts(array('lang'      => '',), $atts));
    $lang_active = ICL_LANGUAGE_CODE;   
    if($lang == $lang_active){
        return $content;
    }
}
 
Shortcode: [wpml_translate lang=en] Content [/wpml_translate]
Edited by dbarrera
1 person likes this

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

Glad you got it working, thank you for updating the thread with the solution.

1 person likes this

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

 

Eventually got it to work with the following:

 

Created the shortcode in functions.php:

 

function webtreats_lang_test( $atts, $content = null ) {
    extract(shortcode_atts(array('lang'      => '',), $atts));
    $lang_active = ICL_LANGUAGE_CODE;   
    if($lang == $lang_active){
        return $content;
    }
}
 
Shortcode: [wpml_translate lang=en] Content [/wpml_translate]

 

 

 

Could you clarify this solution? This seems awesome but I cannot get it working. 

Is that all the code that should go to functions.php ? Where is the "wpml_translate " -part in the function?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

I haven't ever used the WPML plugin, but a quick search for that shortcode returned the following post - http://wpml.org/forums/topic/wpml-shortcode/

 

If you're still struggling, I recommend you post on their support forum for assistance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now