How do you show the last login date of the user in the WordPress site?
We are constantly trying to ensure that we resolve all the queries that the readers have regarding their WordPress site. WordPress is a huge topic and as a result it might not be very easy to understand all the aspects of it easily. We in our articles try to simply explain all the aspects of WordPress for the users who are new as well as using the WordPress for some time. The WordPress users often need to know how exactly they can show the last login date to the users who are logging to the site. You can show this information to the users and we will tell you in simple steps how you can make this possible. You will get videos to explain the same but if you want a detailed step by step guide then you will have to read this article.
There are actually two methods to do this and we will be explaining each one in detail. The two methods are:
- Show the user’s last login date in the WordPress Admin Area.
- Manually show the user’s last login date in WordPress.
We will now explain the two methods in details.
- Show the user’s last login date in the WordPress Admin Area – This is an easy method compared to the second method that we will be discussing later. This is something that can be done even by those who are using the WordPress for the first time. However, with this method you will be able to show the last login date of the user only inside the WordPress admin area.
To do this the first thing that you need to keep in mind is that you will have to install and activate the plugin called the “WP last login” plugin. We have a detailed guide on how you can install and activate the WordPress plugins and you can refer that article to do the same in case you do not know how to install the plugins as you are new to WordPress.
After you have activated the “WP last login” plugin you can move to the next step. In this step you will have to visit the “users” page and then you will have to go to the admin area. In the admin area you will get to see a new column that that will show the last login date of all the users who have been logging to the WordPress site. When you just start with the plugin it will show the status as never logged in because the plugin must be activated to capture the date of last login. After the “WP last login” plugin is activated any user who logs in the date of logging will get captured automatically. We are enclosing a screenshot to show how this appears so that you get a better idea of what we are saying.
- Manually show the user’s last login date in WordPress – The second method that we will be discussing is to manually show the user’s last login date in WordPress. This is a little complex when compared to the first method and we will not recommend it to those who are using WordPress for the first time. The best part about this method is that you can ensure that the last login date of the user in your site can be displayed on any part of the site. To do this a code has to be added to the functions.php file of the theme you can also add the code to the site-specific plugin. As it involves code we say that it is a little more complicated method than the first one that we have already discussed.
You must know well how to copy paste a code from the web. We are enclosing the screenshot of the code. This code will add the last login as a meta key. Each time a user will log in this code will ensure that the time is saved as a meta key value. If you want to check the plugin you will have to logout of WordPress and then login again.
After you do that you can display this meta key value using the [lastlogin] shortcode in your WordPress posts and the widgets. Some users may want to show the last login information as the child theme to do this the following code has to be added.
This code will display a relative date and tie for example “2 hours ago” and not the full date or time. Some users may want to see a full date and time in that case the enclosed code has to be searched in the code that we have mentioned above.
After you get this code you will have to replace it with the following lines of code.
You may get confused about what the M j,y h:I a is about well it is nothing but the date and time format string that you will find in the code. If you want you can change the display date and time format of the code.
We hope that after reading this article you will know how the last login date of the user who has visited your site can be displayed in a WordPress site. The two methods are simple and after the step by step explanation that we have provided you should be able to implement the methods with ease.