Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

want to know who is login in my wordpress website if admin login then go to dashboard and if user login then go to homepage

Approach: I used this code

<?php if ( is_user_logged_in() ) {

   echo ‘ user is loin ‘ ;

} else {

 echo ‘ Not Login ‘ ;

} ?>

and

if(is_admin()) { ...output my admin stuff....}

but doesn't work. any help would be extremely appreciate.

share|improve this question

2 Answers 2

is_admin() only checkes if the dashboard page is displayed or not, if you want to tell the role of a user, try current_user_can( $capability )

share|improve this answer
    
i used this but its not working. if(current_user_can('admin')){ echo 'The current user is an admin'; } if(current_user_can('subscriber')){ echo 'The current user is an subscriber'; } –  Jassi Oberoi Apr 17 '12 at 14:02
    
i applied in header.php file so is that a right file to insert that code? –  Jassi Oberoi Apr 17 '12 at 14:03
    
@jassi9911 The default admin role is called "administrator", not "admin". Try current_user_can('administrator'). –  MathSmath Apr 17 '12 at 16:45
    
just find this Do not pass a role name to current_user_can(), as this is not guaranteed to work correctly. –  Sola Jul 6 '12 at 14:34

ok finally i solved my own problem here is the solution

get_currentuserinfo() ;
if ($user_level > 0) { // if admin login
    echo "admin login";
} else {
    echo "user login";
}
share|improve this answer
    
User levels are deprecated, use current_user_can() with appropriate role or capability instead. –  Rarst Apr 17 '12 at 14:49
    
current_user_can() i used it and its not working:( –  Jassi Oberoi Apr 17 '12 at 15:44
    
Downvote: user levels are deprecated. Don't use this solution. –  MathSmath Apr 17 '12 at 16:46

Your Answer

 
discard

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.