Skip to content Skip to sidebar Skip to footer

Adding A Code To Wordpress Header Based On Local Language Into Functions.php

I have to add a Javascript code to a WordPress header based on the current language used by the website. We use WPML string translation. I want to write a function like this: funct

Solution 1:

Your overall idea should work fine, however, in the example you posted, there were some syntax errors.

functionadd_customcode_header(){
if(ICL_LANGUAGE_CODE == 'ru')
  {
    echo'<script>
              code 1
          </script>';
} 
  else
  {
    echo'<script>
              code 2
          </script>';
  }
}
add_action('wp_head', 'add_customcode_header');

or

    function add_customcode_header(){

    if(ICL_LANGUAGE_CODE == 'ru')?>

        <script>
    code 1
    </script><?phpelse?><script>
    code 2
    </script><?php
    }  
    add_action('wp_head', 'add_customcode_header');

Should both be syntactically correct, and it really just matters what you're more comfortable with.

Post a Comment for "Adding A Code To Wordpress Header Based On Local Language Into Functions.php"