WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use this function to detect if administrator is logged in wordpress

define('WP_USE_THEMES', false);

global $current_user;
$user_info= get_userdata( $current_user->ID );
     if ($lvl == '8' || $lvl == '9' || $lvl == '10')
     echo 'You are admin';

doesnt there exist the easier way?

share|improve this question
if(current_user_can('administrator')) – Howdy_McGee Aug 2 '13 at 17:06
What your code suggests is that you use some kinda bootstrap to laod WP functions outside WP but even in this case you can use what Howdy_McGee says -> see documenation – JMau Aug 2 '13 at 17:19

current_user_can will accept a role name but, sadly, the behavior with roles is not entirely consistent.

The following should work and is simpler than what you have, by a little bit.

$current_user = wp_get_current_user();
if (user_can( $current_user, 'administrator' )) {
  // user is an admin
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.