Checking for cookies returns correct result only inside Elementor Editor

Question

I am trying to check the value of cookies set.

add_shortcode('check_cookies', 'check_cookies_for_category');

function check_cookies_for_category($atts){
    $atts = shortcode_atts(     array(
    'taxonomy' => '',
    ),  $atts
    );

    $terms = $atts['taxonomy'];

    if(isset($_COOKIE[$terms])) 
    {
        return 1;   
    } 
    else
    {
        return $terms;
    }
}

When I view this shortcode inside my elementor editor, it gives back correct result.
"1"
And once I check it on the live website, it says that the cookies are not set. ?
"science" <= cookie term value
How can I make it work on the frontend website as well ?

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/checking-for-cookies-returns-correct-result-only-inside-elementor-editor/">

Checking for cookies returns correct result only inside Elementor Editor</a>
0
Bhanu 2 months 0 Answers 27 views 0

Leave an answer