Setting a Custom Cookie in WordPress only for Logged In User (non-admin)
-
I want to create a custom cookie with custom name only for customers who have once logged in. It should be created after they successfully logged in. It should be deleted after they logged out completely. I am using this code below. For some reason it is not working. Can someone throw some light?
// To Add Cookie add_action('wp_login', 'add_custom_cookie'); function add_custom_cookie() { if(is_user_logged_in()) { setcookie('cookie_name', 'cookie value'); } } // To Remove Cookie add_action('wp_logout', 'remove_custom_cookie'); function remove_custom_cookie() { setcookie('cookie_name', 'cookie value'); }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Setting a Custom Cookie in WordPress only for Logged In User (non-admin)’ is closed to new replies.