I am trying to set a cookie on click via
setcookie('mycookie', 1, time()+60*60*24;
but I can not seem to get it working . If i click the button - when I check my cookies, it is not there .
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityCookies are set on the session BEFORE the page starts to load. Therefor - This function will set the cookie for the NEXT time the page is requested.
you can not (as far as I know ) set a cookie onclick without any javascript help, becasue when at the time the page is rendered (and your click button) - all the cookies are already set.
If you are familiar with jQuery - there are some very good plugins that can help you set a cookie via JS and "refresh" the cookies session. Some of them , will actually refresh the cookie in a way that will trigger also the "normal" wp cookie to be updated .