简体   繁体   中英

How to add condition based on logged in user in wordpress?

I need some help to show specific content for specific user. Expecting something similar to below

if( is_username('john')
{
  $echo 'Welcome john. You are from india.';
} else {
  $echo 'You have no rights to access this page...';
}

it should check condition only by username (text) not by user_id or any integer. Possible??

Use get_currentuserinfo() then compare $current_user->user_login with the username you want to check for.

for example:

get_currentuserinfo()
if($current_user->user_login == 'the_username') {
    echo 'woop';
} else {
    echo 'nope';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM