How do I add nopin="nopin" to the default avatar?

I noticed that if someone clicks on my Pinterest share button on a blog post, several unrelated images show up. I was able to use nopin=nopin per Pinterest's documentation on most of these images to clean most of it up.

However, I have a custom avatar set in my functions.php...

//* Add new default gravatar to Settings » Discussion page */
add_filter( 'avatar_defaults', 'wpb_new_gravatar' );
function wpb_new_gravatar ($avatar_defaults) {
$myavatar = 'https://www.fakedomain.com/wp-content/uploads/2017/03/PiggyBank.jpg';
$avatar_defaults[$myavatar] = Default Gravatar;
return $avatar_defaults;
}

If someone gets that avatar in a comment, then the image shows up as a choice on a Pinterest share. How do I add the nopin=nopin attribute to this avatar image?

I found a similar post discussing this issue, but it's way over my head and seems a little different because he's using an array (lol, also over my head).

Any help is greatly appreciated!

Topic gravatar avatar customization Wordpress

Category Web


You can try this one:

function wp_ste_add_nopin_args( $args ) {
    $extra_attr = 'nopin="nopin"';
    $args['extra_attr'] = $extra_attr;
    return $args;
}
add_filter( 'get_avatar_data', 'wp_ste_add_nopin_args', 999, 1 );

For further reading, please visit: https://developer.wordpress.org/reference/functions/get_avatar_data/

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.