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

Use another action instead of the shortcode API to display the last time a user logged in

You don’t need to store that information, WordPress already does this, and it does this across multiple sessions.

If you log in on your phone, and on your PC, then go to your user in WP Admin, you’ll see them listed with a button to log you out on the other devices.

Additionally, WordPress stores the IP, expiration, and time the session began.

Here’s a simple snippet that will reveal this information in the user edit screen:

<?php

add_action( 'show_user_profile', 'show_sessions_debug' );
add_action( 'edit_user_profile', 'show_sessions_debug' );

function show_sessions_debug( $user ) { ?>
    <table class="form-table">
        <tr>
            <th><label for="user_sessions_debug"><?php _e("Sessions"); ?></label></th>
            <td>
                <pre><?php var_dump( wp_get_all_sessions() ); ?></pre>
            </td>
        </tr>
    </table>
    <?php
}

enter image description here

Related Posts:

  1. Why are you using add_action for shortcode?
  2. How do I use add_action from a class method?
  3. Using action hooks inside of a shortcode
  4. Pros and cons of actions over shortcodes
  5. Enclosing Shortcode Within Another Enclosing Shortcode Breaks Output Functionality
  6. passing parameters to do action from shortcode to wp_footer
  7. Login form from shortcode doesn’t redirect after successful login
  8. OOP and WordPress shortcode
  9. How can I collect and output all attributes of all executed ShortCodes?
  10. Modifying the wordpress login page and then referencing it with a shortcode problem
  11. Processing a login/register form before shortcodes are rendered?
  12. How to create a custom shortcode for custom login form?
  13. Set redirect for need login
  14. i want to show a modal when user lands on home page very first time
  15. Redirect per shortcode if user is logged in
  16. Cannot modify class property from shortcode handler function
  17. Custom Login in Shortcode got error
  18. How to create shortcode for auto login after registration
  19. Which method to use when deleting posts from the front-end
  20. convert it into short code & explan how? [closed]
  21. Enqueue Scripts / Styles when shortcode is present
  22. Conditionally Loading JavaScript/CSS for Shortcodes
  23. What does extract( shortcode_atts( array( do?
  24. Is there a hook that runs after a user logs in?
  25. How do I escape a ‘]’ in a short code?
  26. Pass boolean value in shortcode
  27. Show shortcode without executing it
  28. Shortcode always displaying at the top of the page
  29. Why do some hooks not work inside class context?
  30. PHP error with shortcode handler from a class
  31. Redirect function inside a Shortcode
  32. How to create a shortcode with 1 parameter (atts)
  33. how to show the syntax of a shortcode
  34. Custom shortcode being executed when saving page in wp-admin
  35. Change appearance of shortcode text inside editor
  36. current_shortcode() – detect currently used shortcode
  37. shortcodes output before content [duplicate]
  38. WordPress plugin shortcode not working
  39. How to add stylesheets only to pages with specific shortcode?
  40. Using get_option() in JavaScript
  41. Shortcode empty attribute
  42. Using Ajax with a Class file
  43. How does a shortcode work?
  44. Shortcode outputs at the top of the_content
  45. the_excerpt and shortcodes
  46. Using wp_editor in shortcode
  47. Remove wpautop from shortcode content / remove whitespace in buffering
  48. Get current post id witout passing in shortcode
  49. How to get URL param to shortcode?
  50. How to add multiple buttons to TinyMCE?
  51. Does an activated plugin automatically mean its methods are available to other WP functions?
  52. Check if post/page has gallery?
  53. Get first video from the post (both embed and video shortcodes)
  54. Get shortcode name from within it’s callback function? [duplicate]
  55. Wordspress add into my javascripts
  56. Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation
  57. How do I create a Shortcode that returns text if domain is .com, not .co.uk
  58. Using preg_replace to separate gallery from the_content?
  59. Remove specific shortcode from get_the_content()
  60. How to display the site name in a WordPress page, or post
  61. Hide/show content starting in the middle of a paragraph
  62. Combining shortcode and get_template_part
  63. How can I put a wp_redirect into a shortcode?
  64. Escaping quotes from shortcode attributes
  65. Run visual composer code in php page
  66. short code output too early
  67. Shortcode in shortcode: How to append variable?
  68. Remove wptexturize from a shortcode?
  69. How can i put an array as variable in shortcode_atts?
  70. Autoembeds don’t work with paragraphs
  71. Table of Contents with a shortcode
  72. Create custom [sourcecode] shortcode, the right way?
  73. TED talks shortcode not working
  74. Allowing shortcodes inside attributes
  75. What is the best way to enable nested shortcodes?
  76. Tinymce – How to hook before or after live shortcodes rendering?
  77. How to customize a shortcode using the customizer
  78. Native “playlist” shortcode random playing… How?
  79. How to Output HTML tags in do_shortcode?
  80. List of all inbuilt WordPress shortcodes
  81. Nested Shortcode Detection
  82. Shortcode output always showing at top of page
  83. Organizing shortcodes. How to display all of them and their attributes?
  84. How to detect if a Shortcode is being called on a page?
  85. How to get current page title inside a page itself in a shortcode and in page content
  86. how to have the gallery shortcode output one single UL list instead of several DL?
  87. Implement If-ElseIf-Else-EndIf with short codes
  88. Short code to display a loop
  89. Using shortcode in Post title
  90. using html as shortcode attribute
  91. shortcode outputs first before the page content [duplicate]
  92. Run javascript code after wp_login hook?
  93. How to add ‘class’ attribute into shortcode [audio]?
  94. Make shortcode work with nested double quotes
  95. Get all posts containing a shortcode
  96. How to display the names of users from a specific group with a shortcode?
  97. Autogenerate wordpress shortcodes using array?
  98. WordPress adds br in between my shortcode
  99. Stray closing paragraph tag when using shortcodes
  100. How to display html in a shortcode
Categories shortcode Tags actions, login, oop, shortcode
Trying to hide a button on a specific WordPress Page ID
Site Health says I’m running an older version of PHP even after I upgraded to 7.4.4

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