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. Appropriate WP hook to use set PHP cookie
  29. is_user_logged_in() doesn’t work after custom login and redirect
  30. Cookies vs. sessions
  31. How do I expire a PHP session after 30 minutes?
  32. Is there a way to send HTML formatted emails with WordPress’ wp_mail() function?
  33. How to get WordPress’ hooks/actions run sequence?
  34. Where can I find a list of WordPress hooks?
  35. Is there a save_post hook for custom post types?
  36. Where is the right place to register/enqueue scripts & styles
  37. How to know what functions are hooked to an action/filter?
  38. How to hook update_post_meta and delete_post_meta?
  39. Are there any hooks that alter the 404 logic?
  40. Can’t log in: “ERROR: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.”
  41. Difference between do_action and add_action
  42. WP Cron Doesn’t Execute When Time Elapses
  43. Login page ERROR: Cookies are blocked due to unexpected output
  44. WooCommerce: change display order of product short description and price [closed]
  45. Why do some hooks not work inside class context?
  46. Preventing session timeout
  47. Difference between after_setup_theme and init action hooks?
  48. get $post in init filter or action?
  49. How reduce wordpress login session timeout time?
  50. Use wp init hook to call other hooks?
  51. How many times can I hook into the same action?
  52. How do I implement the WordPress Iris picker into my plugin on the front-end?
  53. How to intercept a 404 error
  54. Move excerpt meta box to above content editor
  55. Action hook for custom tax edit
  56. Trigger custom action when setting button pressed
  57. What is “all” in isset($wp_filter[‘all’])
  58. Whats worth using add_action when we can simply use add_filter?
  59. Is there a limit to hook priority?
  60. Please explain how these hooks work
  61. How to share cookies and sessions between domain and subdomain?
  62. Add_action to wp_head via functions.php
  63. Hook after image is uploaded and image sizes generated
  64. Hook that fires when admin setting is saved
  65. add_action(‘wp_ajax_[action name]’, myfunction) problem
  66. Is it possible to transfer a WordPress session to a different browser via query string?
  67. WordPress auto login after registration not working
  68. What is the difference between update_post_meta and update_postmeta hooks?
  69. wp_set_auth_cookie() doesn’t work in Ajax call
  70. Hook ‘wp_enqueue_scripts’ priority has no effect
  71. Hook on trash post
  72. Hook *after* user password change?
  73. Auto-retrieve YouTube Image for Thumbnail?
  74. Which hook if user profile information is updated?
  75. How to remove action hook done in a plugin from functions.php in my theme?
  76. Hooks for trashing, deleting, saving, restoring custom post type
  77. Disable WordPress 3.6 idle logout / login modal window / session expiration
  78. Is there a WordPress core & plugins update action hook?
  79. Hook into WordPress update?
  80. How to pass users back and forth using session data?
  81. trigger save_post event programmatically
  82. Implementing advanced add_* function wrappers
  83. Adding onload to body
  84. Allow up to 5 Concurrent Login Sessions
  85. My add_action (wp_footer, ‘method’) is not calling?
  86. Passing Additional Parameters to add_filter Callable
  87. Do WordPress Core Filenames Work as Hooks?
  88. What is the earliest possible hook for safely using `is_front_page`?
  89. switch_to_blog(): Load textdomain
  90. How to call a REST endpoint when a post is published?
  91. How should you hook a session_start() when authoring a plugin?
  92. __NAMESPACE__ with register_activation_hook
  93. How to fake a WordPress login?
  94. Does wp_logout_url() destroy a session? (Logging out question)
  95. Init action hook running late after PayPal’s return url?
  96. Can I hook inside another hook?
  97. Adding function directly vs using hook in function.php
  98. Are hooks called synchronously?
  99. How to check if which hook triggered the call to a function?
  100. How can I send to multiple Contact Form 7 recipients based on form input? [closed]
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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