February 5

Check If User Is Logged In

This code checks whether a user is logged in and if they are, you can display special messages, links, images just about anything in HTML or otherwise. This is a great snippet to use in WordPress powered membership sites where you cant to display messages or links only if the user is registered and logged into their account.

Sample Code
if ( is_user_logged_in() ) {
 ?>HTML code here<?php } ?>
Example usage in sidebar
if ( is_user_logged_in() ) {
<li><a href="">Member's Dashboard</a></li>
<li><a href="">Other link</a></li>
<?php } ?>

You do not have to use this in the sidebar it can be anywhere in a Page Template for example. But you need to edit the theme directly. If you do not want to edit the theme, then you will need to install two plugins to make it possible to use PHP code in widgets and in Posts or Pages.


You may also like

Force cPanel Password Reset

Force cPanel Password Reset
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Get in touch

0 of 350