How to replace your login link’s string!

When you login wordpress, your blog’s login link change “Site admin” link. Now my friend ask me. How can add login user’s name in this link’s string.

I tell he “No problem!”. and I goto WordPress ‘s site. Check the plugin’s Document.

I try use add_filter ,the code is :

add_filter('wp_register','add_nickname');
function add_nickname($link){
    return $link;
}

1 minute. ….  en! Nothing ! 😥

OK ! I think , I try use google search!

5 minute……  I realy wanna cry~! 😥

Why ? Because wp_register isn’t action function. It is a tags!

The  “register” is action function. So ! Let’ me change the code:

add_filter('register','add_nickname');
function add_nickname($link){
	global $current_user;
	$name = ($current_user->nickname)?"Hello! <strong>".$current_user->nickname."</strong> ":'';
	if($name){
		preg_match('/href=[\',"](.*)[\',"]/is',$link,$link);
		$link = "<a ".$link[0].">".$name."</a>";
	}
	return $link;
}

OK ! Succeed!



发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

无觅相关文章插件,快速提升流量