? 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.
- 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.
- 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
};