Content Marketing
WordPress: How To Check If The User is Logged, Determine Their Role, And Modify Content

We have a lot of authors on Martech Zone but not all of them are familiar with WordPress and how to log in and publish on the site. WordPress can identify whether or not you’re logged into the platform using a user_level function that returns whether or not you’re logged in as well as what your role is.
Check User Role for Logged In WordPress User
WordPress has several default roles and capabilities:
- Super Admin – somebody with access to the site network administration features and all other features.
- Administrator – somebody who has access to all the administration features within a single site.
- Editor – somebody who can publish and manage posts including the posts of other users.
- Author – somebody who can publish and manage their own posts.
- Contributor – somebody who can write and manage their own posts but cannot publish them.
- Subscriber – somebody who can only manage their profile.
You can dynamically change the displayed link on your site using this snippet using WordPress’ API… displaying the admin link for an author, but displaying an advertise link for anyone that isn’t logged in:
$user = wp_get_current_user();
if ( in_array( 'author', (array) $user->roles ) ) {
wp_register('<li class="menuitem">','</li>');
} else {
echo "<li class='menuitem'><a href='https://martech.zone/advertise/' title='Advertise'>Advertise</a></li>";
}
?>