0

The site I am working on uses banner/popup alerts for emergency situations in the community. I need to set a cookie so the user sees the alert only once, and upon closing the alert won't see it again. However, I need to ensure the user sees any new alerts that may be created, either on the same day or on subsequent days. So the cookie event needs to be per alert.

Currently I'm loading the alert using theme options in the page header. Also, these are site visitors not admin users, so there is no login info to capture.

Thank you.

5
  • not sure what is the question here. If you want to set a cookie, just set it. What is the specific problem you face in implementing it? Commented Sep 7, 2016 at 18:19
  • Hi @MarkKaplun. Everyone that visits the site sees the alert. Once they close the alert, I need to set a cookie so they won't see it again on another page or during another visit (next day for example) as it's loading in the header. However, if there is a new alert set we need to make sure they see that also. So the cookie needs to be alert-specific, if you will. Like adding an ID to each one.
    – tbain
    Commented Sep 7, 2016 at 18:29
  • Also, a cookie may not be the best solution. I'm not sure so just using that as a starting point.
    – tbain
    Commented Sep 7, 2016 at 18:32
  • I meant that this is kind of basic cookie manipulation question that is not actually very specific to wordprss. What is the code that you have written, and what problems do you have with it? Commented Sep 7, 2016 at 19:32
  • This is WordPress specific. I'm using theme options set by the user on the WP backend to display alerts. It's not as simple as just setting/manipulating a cookie. I need to make sure the user does not see the same alert twice. If it's via cookie, the cookie needs to be set when the user sees the alert, and the cookie needs to be alert-specific so the user can see any subsequent alerts. Cookies may not even be the answer. I've tried md5 to generate a hash, but no luck. Just looking for alternatives. Thanks.
    – tbain
    Commented Sep 8, 2016 at 15:50

1 Answer 1

0

So we were able to get this working using the md5 hash set in localstorage for each alert. If anyone has this same issue, message me. Thanks also @MarkKaplun. Sorry I wasn't as clear as I should have been.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.