Check if logged in user is admin in WordPress

I was working with a plugin that had “private field” that were only displayed to the administrator role, but I wanted them to be seen by any logged in user. Learned a lot along the way while working through this issue.

While there is no direct function to check it a logged in user is an admin, it seems the common practice is the following:


if ( current_user_can( 'manage_options' ) ) {
/* do something for admin users */
} else {
/* do something for everyone else */
}

Very useful little bit!

I actually ended up replacing current_user_can( 'manage_options' ) with is_user_logged_in() to get the desired outcome I was looking for in my specific case.

Leave a Reply

Your email address will not be published. Required fields are marked *