How to Check User Role in WordPress

If you are a WordPress developer then sometimes you need to check a role of a user, for example you want to show particular link to only for registered authors and not for common visitors then the bellow WordPress snippet will help you fine.

 
<?php
 
/**
 
 * Check User Role in WordPress
 
 *
 
 */
 
if( current_user_can('editor') ) {
    // true if user is an editor
}
 
if( !current_user_can('administrator') ) {
    // true if user is not admin
}
 
if( current_user_can('edit_posts') ) {
    // true if user can edit posts
}
?>

Related posts:

Partner with Us

We are providing an exclusive partnership offer to individuals and companies who are interested in setting up their own web design & development company. For more information about how to partner with us, please contact us