Posted on: June 4, 2022 by Editorial Staff - Page Views: 1172
In this article we will show you how to check if the current user is the administrator in WordPress. This will be very useful to check if the current user can execute certain things, like editing a page or something of that kind.
In order to check if your current logged in user is Administrator role or not, you will have to use the function called current_user_can. And to be able to check with that function, you will have to specify the capability (eg: manage_page).
<?php
if ( current_user_can( 'manage_options' ) ) {
//Something that the admin can do
}
<?php
if ( !current_user_can( 'manage_options' ) ) {
//Something that a regular user can do
}
For more information , please visit the official wordpress page.
If you need help with implementation of this function into the code of your theme or plugin, or just need customisation services for wordpress or woocommerce, you can hire us.