questions

How can add username to url in WordPress?

Rate this post

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?

 

✔️Solution:

/* 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 */

    }                   

Leave a Reply

Your email address will not be published.

Back to top button