Title: [Plugin: Polylang] get current language
Last modified: August 20, 2016

---

# [Plugin: Polylang] get current language

 *  [lspcity](https://wordpress.org/support/users/lspcity/)
 * (@lspcity)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-polylang-get-current-language/)
 * Hi,
    today I needed to get the current language w/o the flag. But the function
   pll_current_language() returns only the localization.
 * Because of this I added a new pll-function which returns the language name w/
   o the flag.
    Possible arguments are: echo, show_flag, show_name, link, display_name_as
   All arguments except link work as same as in pll_the_languages. The argument **
   link** returns the current language as link or not.
 * You can now call `<?php echo pll_current_language2(array('show_flag' => 1)); ?
   >` to get the current language name and the corresponding flag
 * Add this to the **include/core.php**:
 *     ```
       // displays (or returns) the language switcher
       function current_language2($args = '') {
       	$defaults = array(
       		'echo' => 0, // don't echoes the output
       		'link' => 0, // don't get as link
       		'show_flag' => 0, // don't show flags
       		'show_name' => 1, // show language names
       		'display_name_as' => 'name', // valid options are slug and name
       	);
       	extract(wp_parse_args($args, $defaults));
   
       	$output = '';
   
       	foreach ($this->get_languages_list(false) as $language) {
       		// continue if not current language
       		if ($this->curlang->term_id != $language->term_id) {
       			continue;
       		}
   
       		$url = $force_home ? null : $this->get_translation_url($language);
       		$url = apply_filters('pll_the_language_link', $url, $language->slug, $language->description);
   
       		$url = isset($url) ? $url : $this->get_home_url($language); // if the page is not translated, link to the home page
   
       		$flag = $show_flag ? $this->get_flag($language) : '';
       		$name = $show_name || !$show_flag ? esc_html($display_name_as == 'slug' ? $language->slug : $language->name) : '';
   
       		if($link == 1) {
       			$output .= sprintf("<a hreflang='%s' href='%s'>%s</a>",
       				esc_attr($language->slug), esc_url($url), $show_flag && $show_name ? $flag.'&nbsp;'.$name : $flag.$name);
       		}
       		else {
       			$output .= sprintf("%s",
       				$show_flag && $show_name ? $flag.'&nbsp;'.$name : $flag.$name);
       		}
       	}
   
       	if(!$echo)
       		return $output;
       	echo $output;
       }
       ```
   
 * Add this to the **include/api.php**:
 *     ```
       // returns the current language
       function pll_current_language2($args = '') {
       	global $polylang;
       	return isset($polylang) ? $polylang->current_language2($args) : false;
       }
       ```
   
 * Maybe this will help someone 😉
 * [http://wordpress.org/extend/plugins/polylang/](http://wordpress.org/extend/plugins/polylang/)

The topic ‘[Plugin: Polylang] get current language’ 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/)

 * 0 replies
 * 1 participant
 * Last reply from: [lspcity](https://wordpress.org/support/users/lspcity/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-polylang-get-current-language/)
 * Status: not a support question