0

I have created a cookie in a plugin with the basic PHP function setcookie().

This cookie is in a function.

I can see the cookie in my browser console in admin but not on front.

I added just after my function :

add_action(  'after_setup_theme', 'nameofmyfunctionwherecookieisset', 0  );

But I see no changes.

My question is, how can I get my cookie both in admin and the frontend ?

I am in WP 4.8

  • Are admin pages secured (https) but front-end pages are insecure (http)? If so, the cookie can't cross that barrier, and you'll need to make the full site either secure or insecure. – WebElaine Jun 23 '17 at 16:02
  • I use https both on front and admin All my pages are secured – FrancoisD Jun 25 '17 at 20:26
  • I've resolved my problem. I hadn't define the cookie path, so I've written this and it works : [code] define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) ); [/code] and put COOKIEPATH as an additional argument to my cookie like : ",COOKIEPATH)" at the end of my cookie where it is set. Now the cookie path is set on "/" on the front. Perfect Thanks – FrancoisD Jun 26 '17 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.