简体   繁体   中英

How to add username to url in Wordpress?

Guys is there a way to get username of the logged in user and append it with site url such as www.my-site.com/username

How can we do this in functions.php?

/* you should try below code to get userid of logged in user and redirect to page with username in URL */
    
    $curret_usedata = get_userdata(get_current_user_id());
    if(!empty($curret_usedata)){
            $uname= $current_usedata->user_login;
            $redirectUrl = get_site_url().'/username='.$uname;
          
            /* redirect code here */

    }                   

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