Title: Change WP language in a PHP loop
Last modified: August 22, 2016

---

# Change WP language in a PHP loop

 *  [HosseinRafiei](https://wordpress.org/support/users/hosseinrafiei/)
 * (@hosseinrafiei)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/change-wp-language-in-a-php-loop/)
 * Hello,
 * I’m a WordPress developer. Recently I developed a multilingual plugin. In some
   sections of my plugin I need to change WordPress language and print some text.
 * Let’s say these 3 languages are installed on my WordPress. I need to switch WP
   language in a foreach loop.
 *     ```
       $langs = array('en_US', 'de_DE', 'es_ES');
       foreach($langs as $lang)
       {
           change_wp_locale($lang); /** I need a code to do this **/
           echo __('Hello', 'my-text-domain');
       }
       ```
   
 * Any Idea? Your help is greatly appreciated.
    Kind Regards,

Viewing 1 replies (of 1 total)

 *  [Rastislav Lamos](https://wordpress.org/support/users/lamosty/)
 * (@lamosty)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/change-wp-language-in-a-php-loop/#post-5625208)
 * After a bit of googling I stumbled upon an interesting topic about this:
 * [How to switch language in WordPress “on-the-fly”](http://stackoverflow.com/questions/17229809/how-to-switch-language-in-wordpress-on-the-fly)

Viewing 1 replies (of 1 total)

The topic ‘Change WP language in a PHP loop’ is closed to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [Rastislav Lamos](https://wordpress.org/support/users/lamosty/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/change-wp-language-in-a-php-loop/#post-5625208)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
