I used a WP hack for displaying author’s pics. For example, my single.php has an author slug which displays the author’s pic.
I created a folder called authors in my theme/images folder. Based on the author’s ID, I name the file 1.jpg, 2.jpg and so on.
So I call this image as
<img src="<?php bloginfo('template_directory') ?>/images/authors/<?php the_author_ID()?>.jpg" alt="<?php the_author(); ?>">
Now i’m modifying a plugin that displays the authors in the sidebar. However this plugin uses the get_avatar function, which is as follows:
/**
* If show avatar option is checked, add get_avatar function to cache.
*/
if($jmetc_options['show_avatar'] == 1) {
$jmevar['cache'] .= get_avatar($tc->comment_author_email, $jmetc_options['avatar_size']);
}
Can someone advise me on how to use/modify the get_avatar in order to use the default code that I use?
The
get_avatar()
function applies aget_avatar
filter hook, that you can use to change the avatar markup:I think this would be the correct way to hook into this filter:
EDIT
p.s. a nice alternative to this approach might be the Simple Local Avatars Plugin.
EDIT 2
The filter is applied using
add_filter()
, notapply_filters()
. That was a typo on my part; fixed now!EDIT 3
I don’t think this is correct:
First, you still call
get_avatar()
in your template file, passing all the same parameters as previous. Theadd_filter()
call belongs infunctions.php
.Second, you can pass additional parameters to your filter function; e.g.:
There is a small error in above’s function
better use this: