[Plugin: Author Avatars List] Using username in shorcode
-
I had a specific need to show author avatars using username (loginname) rather than email or userid. Since I could not find anything, I wrote my first plugin. I am not a programmer and the code below is probably not without problems – but I post it here in the hope that it may help someone.
1. Copy the code below and save it as a php file.
2. Upload the file to your plugins folder and activate it.
3. Where you want the avatar to appear, use [showavatar username=loginname size=number] in the post.<?php /* Plugin Name: Show User Avatar Description: A plugin designed to provide shortcode ability in posts and comments using showavatar shortcode. Valid attributes are username=loginname and size=number. Author: sargespam Version: 0.8 */ add_shortcode('showavatar', 'getuseravatar'); function getuseravatar($atts, $content=null) { extract(shortcode_atts(array( 'username' => '', 'size' => '', ), $atts)) ; $user = get_userdatabylogin($username); $useridnum = $user->ID; $output = get_avatar($useridnum, $size) ; return $output; } ?>
Alternately, I believe you can also use the following code in your theme’s functions.php file rather than making it a plugin.
function getuseravatar($atts, $content=null) { extract(shortcode_atts(array( 'username' => '', 'size' => '', ), $atts)) ; $user = get_userdatabylogin($username); $useridnum = $user->ID; $output = get_avatar($useridnum, $size) ; return $output; add_shortcode('showavatar', 'getuseravatar');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘[Plugin: Author Avatars List] Using username in shorcode’ is closed to new replies.