WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Polylang] Set body class depending on language

[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);
    }

    http://wordpress.org/extend/plugins/polylang/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Chouby

    @chouby

    Thank you for sharing !

    Thank you, namoras!
    could please explain to a newbie how to add the language_slug using the body_class function? I have no clue of css and being able to change header according to the language is really important for my website.
    Thank you in advance!

    Hi! I think that this solution will be easier for what marlora is asking.

    It just work with the templates pages, not the functions or styles.

    Greetings!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Polylang] Set body class depending on language’ is closed to new replies.