WordPress Code Snippets

A fresh mix of code snippets and tutorials

Members-only content via shortcode

147

Here is a sweet little WordPress shortcode to display content only to logged-in users. Visitors not logged in will see a custom message saying whatever you’d prefer.

To implement, just add the following code to your theme’s functions.php file:

Then you can use it to display content to logged-in users only, like so:

[member]Welcome logged-in user..[/member]

Another example, displaying the content of another shortcode to members only:

[member][user-submitted-posts][/member]

Thanks to LapanWebsite for posting this tip on the forums for User Submitted Posts.

Learn more

Digging into WordPress