# Current Language Class on the Body Tag

> Adds classes like lang-fr and dir-rtl to the body tag, so you can adjust styles per language, whether the language comes from WPML, Polylang or the WordPress locale.

- Type: PHP
- Runs: Frontend only
- Category: [Multilingual](https://wpide.com/library/category/multilingual/)
- Tags: body-class, css, language
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/i18n-language-body-class/

## Code

```php
add_filter( 'body_class', function ( $classes ) {
    $code = strtok( str_replace( '_', '-', determine_locale() ), '-' );

    if ( defined( 'ICL_LANGUAGE_CODE' ) && ICL_LANGUAGE_CODE ) {
        $code = ICL_LANGUAGE_CODE;
    } elseif ( function_exists( 'pll_current_language' ) && pll_current_language() ) {
        $code = pll_current_language();
    }

    $classes[] = 'lang-' . sanitize_html_class( strtolower( $code ) );
    $classes[] = is_rtl() ? 'dir-rtl' : 'dir-ltr';

    return $classes;
} );
```

## Notes

""

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Current Language Class on the Body Tag" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
