Quantcast
Channel: Suzanne Ahjira» Tutorials
Viewing all articles
Browse latest Browse all 29

How To Filter The Flint Author Box Avatar

$
0
0

Flint’s author box supports the popular User Photo WordPress plugin. You don’t have to tweak anything to make it work, but what if you want to serve a default image if a user doesn’t have a user photo or a gravatar photo?

No problem.

Flint now has a filter for the author box photo. Here’s an example of how to use it to specify a default image in the event there isn’t a user photo or gravatar.

add_filter( 'flint_author_box_avatar', 'my_author_box_avatar' );
function my_author_box_avatar($avatar) {

  global $post;

  return $avatar = get_avatar( get_the_author_meta( 'email' ), 200, $default = 'http://yoursite.com/images/default_photo.jpg'); 

}

In this example, all we’re doing is using the get_avatar() function to add an additional argument: $default

You can see the first argument get_the_author_meta( 'email' ) tells the function to get the post author’s photo by the email address on file. The second argument, 200, is the size of the avatar to fetch. The third argument is the URL for the image you want to use in the event that no user photo or gravatar image was found for the given author.

Paste that into your Flint skin’s functions.php file, change the size and default URL and you’re good to go with a default user photo.


Viewing all articles
Browse latest Browse all 29