在WordPress url中获取登录用户名

时间:2013-05-30 作者:Arvind07

我想在我的wordpress站点的URL中获取登录用户的用户名。Like if用户:arvind 已登录,我想获取url作为\'www.wp.com/arvind\'\'www.wp.com?user=arvind\'.

有什么解决办法吗?

1 个回复
最合适的回答,由SO网友:Vikas Bhardwaj 整理而成

我想这会满足你的需求。

add_action("template_redirect", \'template_redirect\');
function template_redirect() {
 global $wp;    
     if(is_user_logged_in() && !isset($_GET[\'user\'])){
    $current_user=  get_userdata(get_current_user_id());
    wp_redirect(add_query_arg(array(\'user\'=>$current_user->user_login),home_url($wp->request)));
    die();
}
}

结束

相关推荐

Multiple URLs with Numbers

我正在尝试更正Wordpress网站上的一个问题,该网站正在以以下格式生成重复页面:/关于美国/康涅狄格州/3/3/关于美国/康涅狄格州/3/3/关于美国/康涅狄格州/3//关于美国/康涅狄格州/3/关于美国/康涅狄格州/我无法确定是什么导致了这种情况的发生。有人能提出阻止这种情况发生的方法吗?谢谢Josh