Skip Navigation

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.

This topic contains 1 reply, has 1 voice.

Last updated by Giancarlo 3 years ago.

Author Posts
June 11, 2018 at 9:49 am #2404630

Giancarlo

Tell us what you are trying to do?
I would like to have my body class "en" "de" "fr" etc, basing on the language

Is there any documentation that you are following?
yes, but they lack on details

Is there a similar example that we can see?
hidden link

What is the link to your site?
hidden link

Hi Support Team,
I am getting crazy trying to make this PHP code work. In several topics I read about this and they all suggest to implement the following code inside functions.php

add_filter('body_class', 'append_language_class');
function append_language_class($classes){
  $classes[] = ICL_LANGUAGE_CODE;  //or however you want to name your class based on the language code
  return $classes;
}

But this code alone doesn't work, because you need to call the function inside the index.php, by adding this code

<body <?php body_class(); ?>>

My problem is that with my current theme I am not allowed to change the theme's main header.php, because on the next theme updates I would lose my additional code. I am using a child theme which has no index.php, only css and functions.php

Can you suggest me how to manage this issue, please?

PS: why nobody of the developers has ever thought about adding this as a plugin's option?

June 11, 2018 at 10:05 am #2404652

Giancarlo

Solution found