Check if the Current User is the Administrator in WordPress

If we want to add functionality only for logged-in admins, this can be done with the current_user_can() function. By using current_user_can(‘administrator’) in an if statement, it’ll allow you to check if the current user is a site admin.

<?php
if( current_user_can('administrator') ) {
 echo 'This will display for WordPress admins only.';
};

Additionally, you can target a specific capability of a user.

Leave a comment

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