【问题标题】:How to add username to url in Wordpress?如何在 Wordpress 中将用户名添加到 url?
【发布时间】:2025-11-24 10:30:01
【问题描述】:

各位有没有办法获取登录用户的用户名并将其附加到站点 url,例如 www.my-site.com/username

我们如何在functions.php中做到这一点?

【问题讨论】:

  • 您是说在前端拥有用户配置文件吗?
  • 是的。基本上我打算将每个登录用户重定向到一个定制的页面,该页面只显示他们的画廊。对如何进行感到困惑,所以想到了这个想法
  • 默认情况下 WordPress 没有用户个人资料页面,因此您可能应该从查看会员/用户个人资料插件开始:wpeverest.com/blog/best-wordpress-frontend-user-profile-plugins
  • 也可以自定义编码,但具体方法会有所不同,具体取决于您的规格
  • 我安装了前端仪表板插件。它让我可以选择添加自定义帖子和更改用户个人资料数据。但是有没有办法创建使用特定页面。我基本上想在随机页面上向每个在我的网站上注册的客户展示他的婚礼照片

标签: php wordpress authentication redirect


【解决方案1】:
/* 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 */

    }                   

【讨论】:

  • 谢谢,这会有所帮助。你知道我可以在重定向代码区添加什么