0

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!

1 Answer 1

0

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/

2
  • This worked perfectly! Thanks you! There is a small typo in it though if you want to update it for others. You're missing an apostrophe before the semicolon on the nopin line. It should read: $extra_attr = 'nopin="nopin"'; Thanks again - very much appreciated, @Tommy !!
    – Jim
    Commented Oct 25, 2021 at 19:10
  • @Jim updated :) thanks Commented Oct 26, 2021 at 2:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.