Support » Plugin: Polylang » [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

    	$curlang = "none";

    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"); ?>


    	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)

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Chouby


    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.

    I’ve found a solution using get_bloginfo () in here. Check it out!

    Don’t ever change the code on plugins directly. It’s a bad mojo 🙂

    Check my reply at 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.