Title: get active language
Last modified: October 16, 2020

---

# get active language

 *  Resolved [esanchez3](https://wordpress.org/support/users/esanchez3/)
 * (@esanchez3)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/get-active-language/)
 * Hi,
 * Is there any way to get the active language in php?
 * I need to switch the wordpress language along the plugin to translate a plugin::
   after attribute text.
 * The get_locale() function always returns the site default language.
 * Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [edo888](https://wordpress.org/support/users/edo888/)
 * (@edo888)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/get-active-language/#post-13551424)
 * Hi,
 * Please check [How to detect current selected language?](https://docs.gtranslate.io/en/articles/1349939-how-to-detect-current-selected-language)
 * You can check for googtrans cookie to detect the language, but when you switch
   the language it will not execute PHP, as the translations happen on the fly.
 * If you are trying to achieve something, please describe it here, may be there
   is a better way other than changing the locale, which does not seem right to 
   me.
 * You can also check our paid version: [https://gtranslate.io/#pricing](https://gtranslate.io/#pricing)
   which has more features.
 * Thanks! 🙂
 *  Thread Starter [esanchez3](https://wordpress.org/support/users/esanchez3/)
 * (@esanchez3)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/get-active-language/#post-13556019)
 * Hi,
 * Thanks for your answer.
 * We are using the GPDR Cookie Consent plugin, which inserts a text using a data-
   attribute value located in a ::after element. So we are trying to translate it
   by setting the active language as the user language.
 *  Plugin Author [edo888](https://wordpress.org/support/users/edo888/)
 * (@edo888)
 * [5 years, 7 months ago](https://wordpress.org/support/topic/get-active-language/#post-13558459)
 * Hi,
 * If you are using CSS and you need to write language specific rule you can use
   attribute selector. We are setting lang attribute on html tag like this:
 * HTML:
    `<html lang="es" ..>`
 * CSS can be like this:
    `html[lang="es"] .etc {...}`
 * Hope this helps.
 * Thanks! 🙂
    -  This reply was modified 5 years, 7 months ago by [edo888](https://wordpress.org/support/users/edo888/).

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘get active language’ is closed to new replies.

 * ![](https://ps.w.org/google-language-translator/assets/icon-256x256.png?rev=3007649)
 * [Translate WordPress - Google Language Translator](https://wordpress.org/plugins/google-language-translator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/google-language-translator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/google-language-translator/)
 * [Active Topics](https://wordpress.org/support/plugin/google-language-translator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/google-language-translator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/google-language-translator/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [edo888](https://wordpress.org/support/users/edo888/)
 * Last activity: [5 years, 7 months ago](https://wordpress.org/support/topic/get-active-language/#post-13558459)
 * Status: resolved