How to add a class to the <body> for each language?
I want to add a specific class to the <body>
when I switch languages with WPML. I am using English and German right now, so my goal is to get <body class="en">
or <body class="de">
due to the switched on language. H开发者_运维百科ow can I manage that?
You can use the ICL_LANGUAGE_CODE. It's documented here: http://wpml.org/documentation/support/wpml-coding-api/
Something like this would work:
<body class="<?php echo(ICL_LANGUAGE_CODE) ?>">
In Wordpress using q-translate I used this code
add_filter( 'body_class', 'custom_class' );
function custom_class( $classes ) {
if (qtranxf_getLanguage() == 'en') {
$classes[] = 'eng';
}
elseif (qtranxf_getLanguage() == 'ar') {
$classes[] = 'arbic';
}
return $classes;
}
精彩评论