Wordpress Avatar based on username

Posted by mfwl, 02-10-2011, 05:43 AM
I am trying to add a wordpress avatar based on the username, so far I have added the following to the functions.php file in my template to change the default avatar and it works well: Now I can change the $myavatar string to a remote url of an image and that works, however the image I want to use is the avatar icons from xbox. Where the user_login = the members gamertag This is where my problem lies.... Wordpress adds a '&s=64' or a '&s=50' after the url for the image. http://avatar.xboxlive.com/avatar/El...vatarpic-l.png for example works perfectly but http://avatar.xboxlive.com/avatar/El...pic-l.png&s=64 returns an error. Is there a way of removing the '&s=64' or the '&s=50' resize attributes to call the image? Please help, I really would like to set the users avatar in wordpress automatically to match the live image held at http://avatar.xboxlive.com/avatar/{gamertag}/avatarpic-l.png

Posted by Harzem, 02-10-2011, 06:03 AM
Add a hashmark after .png part. It will fix the problem: http://avatar.xboxlive.com/avatar/El...atarpic-l.png# http://avatar.xboxlive.com/avatar/El...ic-l.png#&s=64

Posted by mfwl, 02-10-2011, 06:04 AM
Thanks so much for that I will try it!

Posted by Harzem, 02-10-2011, 06:05 AM
I edited my post seconds ago, try again.

Posted by mfwl, 02-10-2011, 06:13 AM
for some reason it doesnw work it adds the # to the end... if ( !function_exists('fb_addgravatar') ) { function fb_addgravatar( $avatar_defaults ) { $myavatar = "http://avatar.xboxlive.com/avatar/elusiveleader/avatarpic-l.png#"; $avatar_defaults[$myavatar] = 'xboxrox'; return $avatar_defaults; } add_filter( 'avatar_defaults', 'fb_addgravatar' ); } http://avatar.xboxlive.com/avatar/el...atarpic-l.png# produces: http://avatar.xboxlive.com/avatar/el...ic-l.png&s=64# This still errors??

Posted by mfwl, 02-10-2011, 08:32 AM
I have fixed the above error by installing add-local-avatar plugin I have in my functions.php: if ( !function_exists('fb_addgravatar') ) { function fb_addgravatar( $avatar_defaults ) { $myavatar = "http://avatar.xboxlive.com/avatar/{$username}/avatarpic-l.png"; $avatar_defaults[$myavatar] = 'xboxrox'; return $avatar_defaults; } add_filter( 'avatar_defaults', 'fb_addgravatar' ); } But the image returns: http://avatar.xboxlive.com/avatar//avatarpic-l.png How do I insert the users username to the above url???

Posted by mfwl, 02-10-2011, 09:59 AM
Tearing my hair out here trying to set the default wordpress avatar using the username of the member in the url to the image! All I want to do is get the username of the member to be included in the url.. why won't it work?? in my functions.php of my wordpress theme I have defined a default avatar as follows: Am I not referencing the username correctly? Am I not inserting the string correctly in the url? If I typ in a username eg elusiveleader into the url it gets the image! I just want to get this working!!! Please help!

Posted by Squidix - SamBarrow, 02-10-2011, 10:30 AM
Because you have single quotes around the url. If you want to use variables within a string you need to use double quotes.

Was this answer helpful?

 Print this Article

Also Read

Released Sql Server 2008 Express without SSMSE 08

Posted by IceDog, 08-18-2008, 12:27 AMI'm sure most of you know that they released the Sql Server...

Extension issue

Posted by imad77, 04-20-2009, 10:39 AMHi, I run a Perl/CGI script from a Web page to download...

Recommendation

Posted by endin, 06-26-2008, 08:37 AMHi, please Recommendation for install script to faster...

Websites hacked, can't find the file

Posted by crk91, 04-20-2009, 09:30 PMI don't know how this happened but someone got into my VPS...

dba_insert() not working

Posted by latheesan, 01-09-2008, 08:30 AMHello, I am trying to create a class to handle dba in...