Call Us Now : 1 646 568 5447
19 Mar/12


Anil Gupta

Daily Tip: How to Check If a WordPress User is Logged In


Here’s a quick tip for showing different content with WordPress based on whether a user is logged in or not. You can replace the text with an image or link or anything you like. Use it in your sidebar, header, footer or any template in your theme where you want to display content conditionally.

<?php

if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
} else {
    echo 'Welcome, visitor!';
};
?>

This snippet comes to you courtesy of our friends at WP-Snippets, a great resource for finding WordPress hacks and learning a few new skills. Subscribe to the WP-Snippets feed for more useful bits of code.

Categories : Weblog WordPress News