Check if WordPress User is Logged in

Check if WordPress User is Logged in

? The Snippet:

if ( is_user_logged_in() ) {
    echo 'Welcome, logged in user!';
} else {
    echo 'Welcome, visitor!';
};

ℹ️ About the Snippet

Want to show something specific for a logged in users? Want to hide something from not logged in users? This small snippet can be used to check if a user on your website is logged in or not and based on that you can show specific content to them.

✅ How to use the Snippet

To use this snippet, you only need to have a basic understanding of file editing in WordPress. Below are the steps you’ve to follow.

  1. Edit Required File

    Go to your theme directory either by FTP or from Appearance->Editor. If you’re on localhost, you can open the theme files in any Code Editor/IDE.

  2. Paste the below Code Snippet

    Find the right place where you want to show/hide some content based on the user’s logged in status and paste the below code snippet:

if ( is_user_logged_in() ) {
    // Content for Logged in user
} else {
    // Content for Not Logged in user
};

Sharing is caring!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get regular WordPress updates directly in your inbox.

shares