Title: Language preference cookie custom plugin
Last modified: May 19, 2021

---

# Language preference cookie custom plugin

 *  Resolved [kardoo](https://wordpress.org/support/users/kardoo/)
 * (@kardoo)
 * [5 years ago](https://wordpress.org/support/topic/language-preference-cookie-custom-plugin/)
 * have this custom pligin that im using in order to save the user’s language preferences.
   I store it as a cookie like so:
 *     ```
       <?php
   
           add_filter( 'init', 'aws_set_language_cookie', 999 );
           function aws_set_language_cookie() {
               global $TRP_LANGUAGE;
               if ( isset( $TRP_LANGUAGE ) ) {
                   $result = setcookie( 'language', $TRP_LANGUAGE, time() + ( 30 * DAY_IN_SECONDS ), "/", "" , true, true );
               }
           }
   
           ?>
       ```
   
 * Now if you take a look at the website [https://ugrandchurch.com/](https://ugrandchurch.com/)
   open cookies in inspect element after switching to Spanish. You will see that
   a cookie by the name of “language” created which holds the value of “es_ES” is
   saved but it changes to “en_EN” after 3 seconds.
 * How can I make sure that the value of Spanish “es_ES” is kept instead of being
   taken overriten by “en_EN”.
 * The WordPress language plugin used here is by the name of TranslatePress
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Flanguage-preference-cookie-custom-plugin%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Cristian Antohe](https://wordpress.org/support/users/sareiodata/)
 * (@sareiodata)
 * [5 years ago](https://wordpress.org/support/topic/language-preference-cookie-custom-plugin/#post-14462794)
 * Hi,
 * You need to check if the cookie exists and has a language in it. If it does, 
   do not set it again.
 * So you need to set it only once. Otherwise it will reset on every page load.

Viewing 1 replies (of 1 total)

The topic ‘Language preference cookie custom plugin’ is closed to new replies.

 * ![](https://ps.w.org/translatepress-multilingual/assets/icon.svg?rev=3166541)
 * [TranslatePress - Translate Multilingual sites with AI Translation](https://wordpress.org/plugins/translatepress-multilingual/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/translatepress-multilingual/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/translatepress-multilingual/)
 * [Active Topics](https://wordpress.org/support/plugin/translatepress-multilingual/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/translatepress-multilingual/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/translatepress-multilingual/reviews/)

## Tags

 * [cookie](https://wordpress.org/support/topic-tag/cookie/)
 * [cookies](https://wordpress.org/support/topic-tag/cookies/)
 * [custom plugin](https://wordpress.org/support/topic-tag/custom-plugin/)
 * [language](https://wordpress.org/support/topic-tag/language/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 1 reply
 * 2 participants
 * Last reply from: [Cristian Antohe](https://wordpress.org/support/users/sareiodata/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/language-preference-cookie-custom-plugin/#post-14462794)
 * Status: resolved