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

Need Counter Help

Posted by paulg1981, 01-08-2008, 10:19 AMHello All, This is my first post in Programming so be...

FTP login problem

Posted by crazyaboutlinux, 04-14-2009, 10:42 AMone of my client is facing to connect FTP server...

DNS management problems on DirectAdmin

Posted by Narcolog, 06-02-2012, 06:46 PMNeed to add this 2 lines for domain via DirectAdmin...

permissions

Posted by shakybaky, 06-26-2008, 04:24 AMI have a vps running centos5 WHM/cpanel I recently...

Please help with php coding problem

Posted by registercheaper, 03-06-2010, 01:43 AMI have the following code for a video site. I need...