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:

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

This function should place the script with code 1 contents if the website language parameter is set to ‘ru’ and IF the language parameter is any other, it should add the code 2 for other languages

The magic question is – will this function work properly?

Read more here: Adding a code to WordPress header based on local language into functions.php

Leave a Reply

Your email address will not be published. Required fields are marked *