How to Display Login Status Of Any Post Author in WordPress

by • On Feb 27, 12 15:15pm • 4207 Views

WordPress Tips and TricksAs an author of your blog, you want your visitor to get the impression that you are spending a great deal of time on your blog. May be they might even want to get to know you personally or just want to talk to you. If you are providing any sort of services (consulting, web design, programming etc.) it might be a good idea to let your visitors know that you are “logged in” or “online” right now and available to chat or to contact with you. You can even create a chat room or forum to provide the support to your audience. If that’s the case then I think it’s a good idea to display your login status on your WordPress blog posts since you will get the most of visitors through all the search engines or through link submissions.

Today, in this post I will show you how to display autor’s online or log in status on his or her blog posts. This is a very simple custom made code that I wrote for our site. So far, it worked on our blog site and on our local server but still it’s a good idea to try it out before your add it on your site. If something goes wrong feel free to contact with us, we will get back to you.

This is a very simple procedure. All you have to do is to go to your theme’s functions.php file then copy the code mentioned below and paste it on the file. Don’t forget to click on the “Update” button.

function check_author_status() {
$user_id = get_current_user_id();
$auth_id = get_the_author_id();
if ($user_id == $auth_id) {
echo 'Online';
} else {
echo 'Offline'; } }

You can change the “Online” and “Offline” word with something else. Feel free to customize it anyway you want. Once you are done, go to your single.php template file and call the function within the loop.

<?php check_author_status(); ?>

You are pretty much done. All you need to do now, is to check. Go to your site and click on the post that you wrote before. Take a look at it carefully and see what it shows. Where you want to place it? It’s entirely up to you, as long as you are calling the function within the loop, it really doesn’t matter. I hope you liked our post.

Feel free to subscribe our RSS feed for the latest updates. Share the post if you find it useful.

You can follow us on Twitter, add on your Google+ circle or Like our Facebook page to get the latest news, updates and reviews.