Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to get session token of current user in wp_login hook?

You can’t access the $_COOKIE in this hook. You can only access $_COOKIE after the page HTTP headers are set with the $_COOKIE its mean in the next page.

You have other hook that you can hook into to get the cookies in the function wp_set_auth_cookie() there is this action at the end.

do_action( 'set_logged_in_cookie', $logged_in_cookie, $expire, $expiration, $user_id, 'logged_in', $token );

So you can use it like this:

add_action('set_logged_in_cookie', 'custom_get_logged_in_cookie', 10, 6);
function custom_get_logged_in_cookie($logged_in_cookie, $expire, $expiration, $user_id, $logged_in_text, $token) {
    // do something...
}

Related Posts:

  1. Is there a hook that runs after a user logs in?
  2. Removing username from the ‘wordpress_logged_in’ cookie
  3. Is there a hook before the user is authenticated?
  4. Run javascript code after wp_login hook?
  5. How can I do customizations on login, registration and password recovery forms?
  6. Setcookie works on admin but not front end
  7. after login that will redirect user role into a page
  8. Searching hook to set cookies before and avoid “headers already sent”
  9. How to get login data (session) outside WordPress?
  10. Firing a function AFTER redirect
  11. Setting Cookie with init hook causes ‘header already sent’
  12. Custom action on login and “remember me”
  13. External Authentication, session_tokens not destroyed on logout
  14. PHP header() gives headers already sent
  15. Send along login credentials with comment content
  16. Is it possible to add the_content filter upon login?
  17. One time login on 2 different WordPress sites
  18. How to read and write session data?
  19. Session management issues with WordPRess 404 Error page
  20. Login issue with subdomain installs
  21. Get WordPress logged in username from root domain when WP is installed in a subfolder
  22. Updating user meta data from external link, user not logged in
  23. Cookie cant be read even cookie is present
  24. Why WordPress not logout after I have close my browser?
  25. How to add a new link to the default register form’s footer links?
  26. Does wp_login hook fire on user registration?
  27. Changing login url
  28. is_user_logged_in() doesn’t work after custom login and redirect
  29. add_action(‘wp_ajax_[action name]’, myfunction) problem
  30. wp_set_auth_cookie() doesn’t work in Ajax call
  31. Hook on trash post
  32. Adding onload to body
  33. What is the earliest possible hook for safely using `is_front_page`?
  34. Does wp_logout_url() destroy a session? (Logging out question)
  35. Send data to 3rd party api with wp_remote_post on wp_login
  36. How to customize the WP admin default help contents
  37. deactivated_plugin hook: get the name of the plugin
  38. Is there a hook for user activation (after they click the email confirm)?
  39. Adding body class to login page?
  40. How to hook into user registration process Before user registers
  41. WP Admin Bar frontend issue with dashicon deregister
  42. A good way to add a different background image for each page?
  43. Searching a hook which triggers when deleting a post to get all comments
  44. add_action for lost_password or modify wp-login.php?action=lostpassword
  45. Custom Connect to Facebook, problem logging in/logging out
  46. @wordpress/hooks use to add actions/filters within multiple plugin
  47. How can I customize the upload error message in WordPress?
  48. WordPress hook that gets featured image from direct URL?
  49. WP CLI Get all Enqueued Scripts and Styles
  50. Change username before login
  51. Delay an action until current action is completed
  52. How to properly setup an activation hook
  53. How to remove scripts/style added to customize_controls_enqueue_scripts hook by current active theme
  54. How to remove query string from current page URL?
  55. Plugins rewrite rules the right way
  56. Strange behaviour with add_{$meta_type}_metadata | add_post_metadata filter
  57. How can I get my Script to work on the Login page?
  58. Add nofollow to custom widget posts
  59. Change Password Confirmed Email Text
  60. Session Experies and Get Logged Out Within Few Minutes
  61. Lock user information once fields have been filled in
  62. load-* hook for dashboard
  63. What conditions must be met in order to upload .zip file to a multisite WordPress installation?
  64. How to hook code in ?
  65. wp_enqueue_script before wp_head
  66. Use an array of page template slugs and $hook
  67. Session Cookie security questions
  68. wp_logout hook never triggered
  69. add short description under price
  70. How do I use pre_option_{option_name} correctly?
  71. WordPress media library allow uploading fake file
  72. Hooking dynamic/variable named hook in all cases
  73. What hook to add at start of WordPress load
  74. Knowing if a post is sticky in the ‘save_post’ action. Where do I have to hook?
  75. Count when a post of a custom post type is deleted and store it in a theme option
  76. Can we change the hook firing sequence?
  77. Intercept loading of a certain page
  78. Creating custom post on registration in wordpress?
  79. Display custom user profile fields in wordpress
  80. profile_update not supplying old data
  81. Output Redirect Headers on Admin Dashboard Page
  82. add_image_size not working with after_switch_theme
  83. wordpress hooks
  84. Check when a setting has been changed
  85. add extra parameter in default hook in wordpress
  86. Exclude WooCommerce terminations from YOAST
  87. set_post_format called after wp_update_post when using bulk edit?
  88. add hook restricted only to either plugins or themes?
  89. How to hook watchdog script for existence of a WP page?
  90. addaction hook cause redirection problem
  91. White screen after login attempt
  92. Changing user_login ends current session
  93. Getting all post/page IDs related to a soon-to-be-deleted tag/cat
  94. Hooking get_pages()
  95. Transform .wp-video to the native video player of the browser
  96. Create a Custom Login System in WordPress [closed]
  97. How to use the password_reset hook to validate new password and display error
  98. WordPress keep logged in after browser close
  99. Get post ID before add_theme_support
  100. Is there a way to assign a default Category to a Post when the user creates a new Post?
Categories hooks Tags cookies, hooks, login, session
Loop posts only excluding first post
Site redirecting from http to https [closed]

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress