[Plugin: Polylang] Set body class depending on language
-
I don’t know if this was discussed before (found nothing), but since I now spent a few ours on it, I probably want to know how I did it later on ?? and other might be interested, I put it here.
My theme (Suffusion) does the header image with CSS background-image:, so I needed a different class for each language to be able to CSS-define a different header image in each language. I now put the a class named [language-slug] into the body tag using the body_class function of WordPress. I put the following in the functions.php of my theme child:
add_filter('body_class', 'my_custom_body_class', 10, 2); function my_custom_body_class($classes) { $classes[] = get_bloginfo('language'); return $classes; }
This adds the class name ‘de-DE’, ‘fr-FR’ or ‘it-IT’ to the class list of the body tag, depending on the current language. I now can define the CSS background-image (and of cours other stuff) depending on the language, i.e.:
body.de-DE #header-container { background-image: url(wp-content/themes/suffision-child/images/header-pic-de.png); } body.fr-FR #header-container { background-image: url(wp-content/themes/suffision-child/images/header-pic-fr.png); } body.it-IT #header-container { background-image: url(wp-content/themes/suffision-child/images/header-pic-it.png); }
- The topic ‘[Plugin: Polylang] Set body class depending on language’ is closed to new replies.