Title: Checking if the User is Admin
Last modified: August 20, 2016

---

# Checking if the User is Admin

 *  Resolved [cloudstr210](https://wordpress.org/support/users/cloudstr210/)
 * (@cloudstr210)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/)
 * Hello, I just want to check if the user is admin but I always got error..
 * The error is unexpected > on the code..
 *     ```
       <?php if ( ! is_admin() ) {
   
       } else {
       }
       ?>
       ```
   
 * I want to put adsense script on it.. But I always got unexpected >
 * Thank you.

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/checking-if-the-user-is-admin/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/checking-if-the-user-is-admin/page/2/?output_format=md)

 *  Moderator [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422675)
 * Does this work? I know you want the code in there, but let’s start with this 
   🙂
 *     ```
       <?php if ( ! is_admin() ) {
         echo '<p>adsense!</p>';
       }
       ?>
       ```
   
 *  Thread Starter [cloudstr210](https://wordpress.org/support/users/cloudstr210/)
 * (@cloudstr210)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422805)
 * Does not work too.. This is the error
 * Parse error: syntax error, unexpected T_STRING, expecting ‘,’ or ‘;’ in /home/
   xxx/public_html/xxxx/wp-content/themes/xxx/single.php on line 6
 *  [danhgilmore](https://wordpress.org/support/users/danhgilmore/)
 * (@danhgilmore)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422806)
 * What exactly is on line 6?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422807)
 * There’s nothing wrong with Ipstenu’s code.
 *  Thread Starter [cloudstr210](https://wordpress.org/support/users/cloudstr210/)
 * (@cloudstr210)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422808)
 * I tried this code.. and have no error, but the adsense is still showing even 
   the admin is login..
 *     ```
       <?php if (!is_admin()) { ?>
       <?php include('adsense.php'); ?>
       <?php } ?>
       ```
   
 *  Thread Starter [cloudstr210](https://wordpress.org/support/users/cloudstr210/)
 * (@cloudstr210)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422809)
 * [@danhgilmore](https://wordpress.org/support/users/danhgilmore/)
 * Its the last code of the adsense code.
 * [@esmi](https://wordpress.org/support/users/esmi/)
 * Thanks for the reply.. I know theres nothing wrong in it but its not working 
   for me..
 *  Thread Starter [cloudstr210](https://wordpress.org/support/users/cloudstr210/)
 * (@cloudstr210)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422810)
 * I tried this too..
 * <?php if (!is_admin()) { ?>
    echo ‘<?php include(‘adsense.php’); ?>’; <?php }?
   >
 * But it seem that the function !is_admin is not working?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422811)
 * That code is hopelessly broken. Try Ipstenu’s code again and, this time, make
   sure that you’re adding it to the right place in your template file.
 *  [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * (@big-bagel)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422814)
 * > …I just want to check if the user is admin…
 * Are you trying to check if an administration screen is being shown or if the 
   current user is an administrator? If it’s the latter, then you want something
   like this:
 *     ```
       if ( current_user_can( 'manage_options' ) ) {
           /* A user with admin privileges */
       } else {
           /* A user without admin privileges */
       }
       ```
   
 * [Function Reference/current user can](http://codex.wordpress.org/Function_Reference/current_user_can)
 *  Thread Starter [cloudstr210](https://wordpress.org/support/users/cloudstr210/)
 * (@cloudstr210)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422816)
 * Yup, I need to check if the current user is admin..
 * Do i need to put <?php?
 * could you give me sample with adsense dummy code on it.. thanks!
 *  [whiteatom](https://wordpress.org/support/users/whiteatom/)
 * (@whiteatom)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422817)
 * Yeah.. is_admin() checks if you’re on an admin page.
 * [is_admin()](http://codex.wordpress.org/Function_Reference/is_admin)
 * Try
 *     ```
       <?php if (current_user_can( 'manage_options' )) {
               include('adsense.php');
        } ?>
       ```
   
 * This allows you to choose any role by checking if the current_user_can do any
   particular task. Check the table at the bottom of this link and you’ll be able
   to pick any role by selecting a capability that the role you want can do, but
   not the roles below.
 * [Roles and Capabilities << WordPress Codex](http://codex.wordpress.org/Roles_and_Capabilities)
 *  [whiteatom](https://wordpress.org/support/users/whiteatom/)
 * (@whiteatom)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422818)
 * One more thing.. if you are using more than one PHP command they can all be included
   in the same <?php ?> bracket set.
 * Happy Coding…
 * whiteatom
 *  Moderator [Ipstenu (Mika Epstein)](https://wordpress.org/support/users/ipstenu/)
 * (@ipstenu)
 * 🏳️‍🌈 Advisor and Activist
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422825)
 * cloudstr210 – What I was asking was for you to try _without_ your adsense code.
 * I use is_admin() all the time to show things to my admin account and not my visitors,
   on the frontend of my site.
 * So let’s go back to the beginning.
 * Does EXACTLY this work?
 *     ```
       <?php if ( ! is_admin() ) {
         echo '<p>adsense!</p>';
       }
       ?>
       ```
   
 * DO NOT put your own code in 🙂 We’ll get there, but you have to step through 
   things in order when debugging.
 *  [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * (@big-bagel)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422827)
 * But, `is_admin` just checks if the request was for an administration page. From
   the inline documentation:
 *     ```
       Does not inform on whether the user is an admin! Use capability checks to tell if the user should be accessing a section or not.
       ```
   
 *  [Pioneer Web Design](https://wordpress.org/support/users/swansonphotos/)
 * (@swansonphotos)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/#post-2422828)
 * Comment: It cannot, and will never be, a boon to users in this forum to see three
   folks disagree on how to do things…Shall I believe Emsi (mod), IpStenu (mod),
   or Big Bagel (?)?
 * Am I alone in this sentiment?

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/checking-if-the-user-is-admin/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/checking-if-the-user-is-admin/page/2/?output_format=md)

The topic ‘Checking if the User is Admin’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 20 replies
 * 9 participants
 * Last reply from: [tactiq](https://wordpress.org/support/users/tactiq/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/checking-if-the-user-is-admin/page/2/#post-2423060)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
