[WordPress] How to check if current user is Administrator

DZone 's Guide to

[WordPress] How to check if current user is Administrator

· Web Dev Zone ·
Free Resource

It’s been quite a while since I posted anything on this blog. Have been really busy doing development work for others and could not devote time to blogging.

I have a quick snippet to share, which is most commonly used while programming in WordPress. The following code snippet let’s you check if the current user logged in is an Administrator or not.

function dm_is_admin(){
    return current_user_can( 'manage_options' );

Paste the above code inside functions.phpof the active theme. Please note that I have used the function name as dm_is_admin, since is_admin function for WordPress already exists. However, the built-in is_admin function only checks if you are currently on the WordPress Dashboard or no.

You can use this code snippet to display certain information in the front end only when the Admin is logged in. I use this to display debugging information on any live site, this comes very handy.

Hope this is going to help you, as well!
Stay Digified!!
Sachin Khosla


Published at DZone with permission of Sachin Khosla , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}