How to Use WordPress to Display Content Depending on a User’s Level

Displaying Content Based on a WordPress Users Level
Displaying Content Based on a WordPress User’s Level

Displaying certain information depending on a visitor’s user level can be a very nifty trick to display relevant content to each individual who visits your WordPress site. This way contributors or subscribers can see something different than a new visitor. Another nifty trick is to use this code to only show something to administrators while a new section of the WordPress site is under development.

How to Check if a WordPress User is an Administrator

<?php if (current_user_can(‘administrator’)) { ?>
[html here]
<?php } ?>

This code snippet can be modified to display content based on any WordPress user level. (More info on WordPress’ user levels)

How to Check if a WordPress User is an Editor
<?php if (current_user_can(‘editor’)) { ?>
[html here]
<?php } ?>
How to Check if a WordPress User is a Contributor
<?php if (current_user_can(‘contributor’)) { ?>
[html here]
<?php } ?>
How to Check if a WordPress User is a Subscriber
<?php if (current_user_can(‘subscriber’)) { ?>
[html here]
<?php } ?>

It really is that simple to display content depending on a WordPress user’s level.

Follow wpLifeGuard

« Back to Blog