How to Highlight unread WordPress posts?

You can use update_user_meta() and get_user_meta(), where you can store and retrieve a value related to a key and a user, like ‘read_post_’ . $post_id for example. Inside The Loop, when you’re going to print the article, you can add a condition: if the user has the user meta value ‘read_post_’ . $post_id as false … Read more

Will setcookie work if there is a cache plugin installed?

It will most likely depend on the plugin, but you should also remember that your content might be cached also in caching proxies as well. https://stackoverflow.com/questions/9334393/proxy-cacheing-what-about-cookies In other words, if your output is different to two different users, than you can not use caching. The way to go around this is to make the decision … Read more

Change the user is logged in cookie name

Cookies do not indicate login status. Even if the cookie is not expired it is possible to terminate the session on admin side, and obviously, just the fact that there is a cookie do not mean that the information in it will authenticate. Sounds like you need an actual SSO solution.

Setting a cookie upon specific URL visit

I’ve used this and it works: add_action(‘init’, ‘optin_cookie’, 1); function optin_cookie(){ $currentURL = “https://” . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’]; if ( $currentURL == ‘https://25dni.si/delovanje-uma/’ ) : setcookie( ‘opt_in’, has_opt_in, time()+31556926, “https://wordpress.stackexchange.com/”); elseif ( $currentURL != ‘https://25dni.si/’ ) : if ( ! isset( $_COOKIE[‘opt_in’] ) ) : endif; endif; } I’m sure there is a much more … Read more

Cookie only detected when visitor is logged in

ANSWER TO MY OWN QUESTION This was something I had been trying to debug for the last couple of days. And the answer was found by mistake. What caused the error was caching. I had to exempt the cookie from cache in order for it to work as it should. So, if you are experiencing … Read more

Visiting Webpage ONLY after another page was visited. Possible?

You could set a cookie upon contact form submission, then check for the cookie on /page2. If it is not found, wp_safe_redirect() back to /page1. Setting a cookie – You will need to hook into Contact Form 7’s submission – look into their documentation: <?php setcookie( ‘my_cookies_name’, true, 0 ); // This cookie will expire … Read more

How set a cookie from PHP and get it without refresh

You need to use the ‘init’ hook similar to the following: add_action( ‘init’, ‘your_function’); function your_function() { setcookie(‘my_cookie’,’tmp_val’); wp_redirect( get_permalink() ); exit; } } You should add a conditional ‘if’ statement in there to prevent it redirecting on every page though! eg. add_action( ‘init’, ‘your_function’); function your_function() { setcookie(‘my_cookie’,’tmp_val’); if ($my_cookie == “???”) { wp_redirect( … Read more