Skip Navigation

Este é o fórum de suporte técnico para o WPML — o plugin de WordPress multilíngue.

Todos podem ler, mas apenas clientes do WPML podem postar aqui. A equipe do WPML responde no fórum 6 dias por semana, 22 horas por dia.

This topic contains 4 respostas, has 2 vozes.

Last updated by Max 3 mes atrás.

Assigned support staff: Max.

Autor Posts
outubro 20, 2021 às 4:33 am #9823231

orlandoM-6

I want to modify via CSS my panel based on the selected language selected in the WPML menu, the same menu used to display the posts that are in that language.

As it does not change the panel language, but rather filters content related to choose, also does not change the "HTML LANG"

Would it be possible to add a Body Class specified to the language that is filtering content?

Example: Body.lang-PT Or Body.lang-EN Or Body.lang-ALL

In my precise case of these 3.

Thanks!

outubro 20, 2021 às 1:43 pm #9827691

Max
Supporter

Languages: Inglês (English ) Francês (Français ) Russo (Русский ) Português (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Olá,

You can use a CSS selector to rely on the "lang" global attribute on the <html> element.

This is more of a CSS question, I invite you do search in the CSS documentation for what you're looking to achieve, for example on this question and answer site: https://stackoverflow.com/

Here's a simple example to get you started (you can replace the "h1" by your own elements that you want to style differently for different languages):

html:lang(en-US) h1 {
    background: orange;
}

html:lang(pt-br) h1 {
    background: blue;
}

Please let me know if you have any more doubts.

outubro 20, 2021 às 6:47 pm #9829769

Max
Supporter

Languages: Inglês (English ) Francês (Français ) Russo (Русский ) Português (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Just thought of another solution with attribute selectors, for example:

[lang] { /* any element with lang attribute */
  background: red;
}

[lang='en-US'] {
  background: skyblue;
}
outubro 20, 2021 às 8:33 pm #9830251

orlandoM-6

Hey!
Sorry, I did not make it clear, but it's on the dashboard I want to use this CSS technique.

It turns out that LANG on the dashboard continues the same when we exchange the language because it is the language of the panel and not the WPML content filter.

What I Want is that on the dasboard / backend Editor Choose View Posts in EN, this is printed on BodyClass for me to hide menus for example ...

outubro 21, 2021 às 7:33 pm #9839043

Max
Supporter

Languages: Inglês (English ) Francês (Français ) Russo (Русский ) Português (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

In this case you can use a hook. Here's a simplified example, I just tested it on my local installation and it's working:

function my_custom_styles() {
    $lang = apply_filters( 'wpml_current_language', NULL );

    if($lang == 'en') {
        echo '<style>
        body {
            background: yellow;  
        }
          </style>';
    }
}
add_action('admin_head', 'my_custom_styles');

Documentation on the hook itself:

https://wpml.org/wpml-hook/wpml_current_language/