• Resolved kardoo

    (@kardoo)


    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/ 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 to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Cristian Antohe

    (@sareiodata)

    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.