Title: [Plugin: Polylang] return the current language as variable for your template
Last modified: August 20, 2016

---

# [Plugin: Polylang] return the current language as variable for your template

 *  [kn00tcn](https://wordpress.org/support/users/kn00tcn/)
 * (@kn00tcn)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-polylang-return-the-current-language-as-variable-for-your-template/)
 * did another little hack
 * at the top of polylang.php, add a new action, let’s say in the template tags 
   section
    `add_action('show_current_language', array(&$this, 'show_current_language'));`
 * then add a new function at the bottom, let’s say after the_languages
 *     ```
       function show_current_language() {
       	global $curlang;
       	$curlang = $this->curlang->slug;
       }
       ```
   
 * in your theme, you can put something like this in your header
 *     ```
       <?php
       	$curlang = "none";
       	do_action('show_kcurrent_language');
       ?>
       ```
   
 * now you can return the slug name of your lang at any time, use it for if statements
   or to load a file, for example, you can put things like this in page.php
    `<?
   php include("sidebar-".$kcurlang.".php"); ?>`
 * or
 *     ```
       <?php
       	if($curlang == "en") {
       		echo "<h3>Latest News</h3>";
       	}elseif($curlang == "fr") {
       		echo "<h3>Dernières Nouvelles</h3>";
       	}
       ?>
       ```
   
 * only 1 problem, the $curlang doesnt seem to get set within the theme header (
   you cant use that if statement example, but it works fine in the other template
   files, index/page/single/category/etc)
 * [http://wordpress.org/extend/plugins/polylang/](http://wordpress.org/extend/plugins/polylang/)

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

 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-polylang-return-the-current-language-as-variable-for-your-template/#post-2371166)
 * I propose a better (im my opinion) solution using only WordPress functions.
 * To know what is the current language for your own use in your theme, you can 
   use the WordPress function get_locale(). It will return something like ‘en_US’.
   You can use this information for whatever you want. It should be available in
   all template files, including header.php.
 * It may also be useful to include the following line in your header.php (if it
   is not already present), just below your doctype:
    `<html <?php language_attributes();?
   >>` It will output something like : `<html dir="ltr" lang="en-US">` I understood
   that this line may be interpreted by browsers and robots to know the page language.
 *  [ChowKaiDeng](https://wordpress.org/support/users/chowkaideng/)
 * (@chowkaideng)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-polylang-return-the-current-language-as-variable-for-your-template/#post-2371217)
 * I’ve found a solution using _get\_bloginfo ()_ in [here](http://wordpress.org/support/topic/plugin-polylang-how-to-translateswitch-specific-contents-on-templates?replies=5).
   Check it out!
 *  [Lopo Lencastre de Almeida](https://wordpress.org/support/users/ipublicis/)
 * (@ipublicis)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-polylang-return-the-current-language-as-variable-for-your-template/#post-2371330)
 * Don’t ever change the code on plugins directly. It’s a bad mojo 🙂
 * Check my reply at [http://wordpress.org/support/topic/plugin-polylang-how-to-translateswitch-specific-contents-on-templates?replies=12#post-2994662](http://wordpress.org/support/topic/plugin-polylang-how-to-translateswitch-specific-contents-on-templates?replies=12#post-2994662)
   for a solution on your ideia and needs.
 * Best and hope it helps others too.

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

The topic ‘[Plugin: Polylang] return the current language as variable for your template’
is closed to new replies.

 * ![](https://ps.w.org/polylang/assets/icon-256x256.png?rev=3433336)
 * [Polylang](https://wordpress.org/plugins/polylang/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/polylang/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/polylang/)
 * [Active Topics](https://wordpress.org/support/plugin/polylang/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/polylang/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/polylang/reviews/)

 * 3 replies
 * 4 participants
 * Last reply from: [Lopo Lencastre de Almeida](https://wordpress.org/support/users/ipublicis/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-polylang-return-the-current-language-as-variable-for-your-template/#post-2371330)
 * Status: not a support question