Title: get_language question
Last modified: August 20, 2016

---

# get_language question

 *  [3×7](https://wordpress.org/support/users/3x7/)
 * (@3x7)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/get_language-question/)
 * I have a question on get_language…
 * it works, just that I would like to modify the output…
 * from “en_US” to only “en”…
 * Thanks!

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/get_language-question/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/get_language-question/page/2/?output_format=md)

 *  [grosshat](https://wordpress.org/support/users/grosshat/)
 * (@grosshat)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189132)
 * I am not sure if you are using an own function `get_language` for fetching ISO
   language. If so, I do not know the specifics of this.
 * If you just want to get the language used on a blog, use the standard call `bloginfo('
   language')`. That returns the ISO, ie. en-US. From there you can decorate it 
   with a helper function so:
 *     ```
       <?php
       $iso = bloginfo('language');
       function get_short_lang( $lang ) {
           $lang = substr( $lang, 0, 2 );
           return $lang;
       }
       ?>
       ```
   
 *  Thread Starter [3×7](https://wordpress.org/support/users/3x7/)
 * (@3x7)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189134)
 * Thanks,
 * I tried with all the code including <?php and it didn’t work.
    I got Parse error:
   syntax error, unexpected… then I’ve put function on the top of my plugin where
   functions are, then where I used `echo bloginfo('language');` I’ve replaced “
   echo” with “$iso”
 * Where did I go wrong?
 * thanks in advance!
 *  [grosshat](https://wordpress.org/support/users/grosshat/)
 * (@grosshat)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189147)
 * Sorry, the code I wrote was wrong, since I was passing `$lang` to the function
   instead `$iso`. And I assumed that you would call the function somewhere to get
   the value.
 * So the right code would be:
 *     ```
       <?php
       $iso = bloginfo('language');
       $lang = get_short_lang($iso);
   
       /**
        * Get the first two letters of a language ISO.
        *
        * @param string $iso
        * @return string $lang
        */
       function get_short_lang( $iso ) {
           $lang = substr( $iso, 0, 2 );
           return $lang;
       }
       ?>
       ```
   
 *  Thread Starter [3×7](https://wordpress.org/support/users/3x7/)
 * (@3x7)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189154)
 * Sorry to bother you so much, I tried all kind of combinations and had no luck…
   
   It actually gets the language with no errors now, but it still outputs the original“
   en-US”.
 * Thanks
 *  [grosshat](https://wordpress.org/support/users/grosshat/)
 * (@grosshat)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189161)
 * Well, do not give up. 😉
 * Are you using the value returned by the function `get_short_lang()` (ie. $lang)?
   This is the value you need.
 *  Thread Starter [3×7](https://wordpress.org/support/users/3x7/)
 * (@3x7)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189169)
 * yes I tried with echo also… no luck…
 *  [grosshat](https://wordpress.org/support/users/grosshat/)
 * (@grosshat)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189170)
 * Where are you calling that code? At `functions.php` level or template level?
 *  Thread Starter [3×7](https://wordpress.org/support/users/3x7/)
 * (@3x7)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189171)
 * From admin panel, it’s an export plugin.
 *  [grosshat](https://wordpress.org/support/users/grosshat/)
 * (@grosshat)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189172)
 * Oki. The code I gave you is working as plain PHP. You can test it and see that.
   The problem could be the way the function is called on the plugin.
 * So, do not call a function, just parse directly the value of the ISO.
 *     ```
       echo substr(bloginfo('language'), 0, 2);
       ```
   
 *  Thread Starter [3×7](https://wordpress.org/support/users/3x7/)
 * (@3x7)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189179)
 * tried that before… strange but outputs “en-US”
 *  [grosshat](https://wordpress.org/support/users/grosshat/)
 * (@grosshat)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189189)
 * That is weird. :/
 * How do you get when you do `print_r` for each value?
 * `print_r(bloginfo('language'))`
    `print_r(substr(bloginfo('language'), 0, 2))`
 *  Thread Starter [3×7](https://wordpress.org/support/users/3x7/)
 * (@3x7)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189190)
 * same “en-US” 😐
 *  [grosshat](https://wordpress.org/support/users/grosshat/)
 * (@grosshat)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189191)
 * Something going wrong. :/
 * If you give the value to a variable and then make a `substr`, what do you get?
 * >  $iso = ‘en-US’;
   >  $lang = substr( $iso, 0, 2 ); print_r( $lang );
 *  Thread Starter [3×7](https://wordpress.org/support/users/3x7/)
 * (@3x7)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189202)
 * This works, I get only “en”
 *  [grosshat](https://wordpress.org/support/users/grosshat/)
 * (@grosshat)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/#post-3189213)
 * Yep. So, why does not work when you use the value returned by `bloginfo('language')`?:/

Viewing 15 replies - 1 through 15 (of 16 total)

1 [2](https://wordpress.org/support/topic/get_language-question/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/get_language-question/page/2/?output_format=md)

The topic ‘get_language question’ is closed to new replies.

## Tags

 * [multi-language](https://wordpress.org/support/topic-tag/multi-language/)

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 16 replies
 * 2 participants
 * Last reply from: [3×7](https://wordpress.org/support/users/3x7/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/get_language-question/page/2/#post-3189215)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
