Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to have a specific image show up for everyone who comments?

add_filter( 'get_avatar' , 'my_custom_avatar' , 1 , 5 );

function my_custom_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
    $user = false;

    if ( is_numeric( $id_or_email ) ) {

        $id = (int) $id_or_email;
        $user = get_user_by( 'id' , $id );

    } elseif ( is_object( $id_or_email ) ) {

        if ( ! empty( $id_or_email->user_id ) ) {
            $id = (int) $id_or_email->user_id;
            $user = get_user_by( 'id' , $id );
        }

    } else {
        $user = get_user_by( 'email', $id_or_email );   
    }

    if ( $user && is_object( $user ) ) {

        if ( $user->data->ID == '1' ) {
            $avatar="YOUR_NEW_IMAGE_URL";
            $avatar = "<img alt="{$alt}" src="https://wordpress.stackexchange.com/questions/180631/{$avatar}" class="avatar avatar-{$size} photo" height="{$size}" width="{$size}" />";
        }

    }

    return $avatar;
}

enter the new image url and paste this code in functions.php
Explaination can be found here.
how to modify avatar

Related Posts:

  1. How do I get the avatar URL instead of an HTML IMG tag when using get_avatar?
  2. Add aditional class to get_avatar when showing image
  3. WordPress login page logo customization
  4. Insert image in comment reply
  5. Use Gravatar as fallback image if no local image is not found
  6. WordPress – different icon image depends of comment number
  7. Disallow img tag in comments?
  8. How do I get a smaller size of an avatar image
  9. Simple Local Avatar Plugin
  10. Allow admin roles to add images to comment replies
  11. Media upload in add comment meta box
  12. Change the avatar ratio?
  13. Convert User’s Avatar/Gravatar to a jpg or png on the Fly
  14. How to add embed image in comments?
  15. Allow unregistered users to post embeded images from other sites in comments
  16. show hide image script after 4 seconds [closed]
  17. Restricting users to view only media library items they have uploaded?
  18. How do I disable responsive images in WP 4.4?
  19. Filter to remove image dimension attributes?
  20. How to get a list of all the possible thumbnail sizes set within a theme
  21. Image Upload from URL
  22. Programmatically adding images to media library
  23. How do I delete all UNUSED images from my uploads directory?
  24. Set default image sizes in WordPress to hard crop
  25. Is it possible set a featured image with external image URL
  26. get attachment title based on attachment id
  27. Stop wordpress from hardcoding img width and height attributes
  28. Handle issues with change of image scaling (rounding) in 4.1 (WP Ticket #18532)
  29. Programmatically get images by URL and save in uploads folder
  30. Prevent WordPress from generating medium_large 768px size of image uploads?
  31. remove or update add_image_size
  32. Get Image Description
  33. How to extend the gallery block in Gutenberg?
  34. Image quality based on image size
  35. Function to get URL of original uploaded image – full size
  36. how to get original image using wp_get_attachment_image_src
  37. What is a good alternative to using $content_width for image optimization?
  38. get the attachement url for the medium sized image
  39. Can I attach image to post without adding it to post?
  40. Automatically replace original uploaded image with large image size
  41. WordPress crop tool greyed out
  42. How to scale up featured post thumbnail?
  43. Upload images to remote server
  44. Custom image size / thumbnail – Crop to aspect ratio even when source image is smaller than set dimensions
  45. Each custom image size in custom upload directory?
  46. Getting Images from theme’s directory in pages
  47. Set default image link target in Gutenberg image block
  48. Add an alignment option for images
  49. How to delete resized (cropped) image uploads and prevent future resizing?
  50. How to automatically add rounded corners to thumbnails?
  51. WordPress adding scaled images that don’t exist (1536×1536 and 2048×2048)
  52. Download an image from a webpage to the default uploads folder
  53. Add image size where largest possible proportional size is generated
  54. WP 4.4. responsive images browser choosing the “wrong” one
  55. After Moving a Site to Another Domain, All Images Are Lost
  56. Prevent WordPress from adding image’ title automatically
  57. Overide Gallery Default Link to Settings
  58. Retrieve featured image
  59. How to change image type for specific size?
  60. Add new image size to media uploader so users can insert into post?
  61. How to insert pictures without hard coded dimensions?
  62. Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
  63. How to modify image editor dialog options on WordPress?
  64. Why WordPress automatic cropping all my images?
  65. Allow contributor role to upload images and not edit already published articles
  66. What’s the proper way to find and remove duplicate images from posts and the media library?
  67. Remove images (files) that were generated when using add_image_size()
  68. get_post_gallery with Gutenberg
  69. Is there a hook which fires after all thumbnails are generated?
  70. Auto Add Image Title,Caption,Alt Text,Description while uploading Images in WordPress
  71. Is there a simple way to just insert a link to an image (without inserting an image)?
  72. Watermarking Images with WordPress with WP_Image_Editor
  73. How to avoid WordPress stripping EXIF metadata when resizing images?
  74. is it possible to replace the use of gd_lib with imagick or ImageMagick?
  75. How to have different captions for same image, for galleries?
  76. Get attachment/image info in JS
  77. How to reference a theme image in a stylesheet?
  78. wp_get_attachment_image_src and server path
  79. Limit image resolution on upload
  80. How to display a page’s featured image?
  81. Separate Media Library for each user
  82. Featured image shortcode
  83. get_post_gallery_images returns thumbs . I want full size
  84. Setting JPEG compression for custom image sizes doesn’t work in specific cases
  85. Maintaining image color and quality when uploading using custom sizes
  86. Rename files on upload
  87. Retina images – custom syntax for inserting images into post content
  88. How to insert images into posts without using Add Media dialog
  89. Using Images in WordPress – Best Practices
  90. How to find attachment by it’s name?
  91. How can I determine if a post has an image attachment?
  92. Media Upload Folder – how to manage
  93. Wrong image dimensions in Insert Media after add_image_size()
  94. How to set the default embed image size
  95. PHP Fatal error: Call to undefined function download_url()
  96. Why is wp_get_attachment_image_src not working with my custom size (add_image_size)
  97. Mixed content warnings after changing site adress from HTTP to HTTPS
  98. How to give image source in wordpress page editor?
  99. What should I do to make generated avatars different for anonymous comments?
  100. Displaying images from external RSS feeds?
Categories images Tags avatar, comments, images, logo
Uncaught TypeError: Cannot read property ‘ajax’ of undefined
Pagination re-direct to main page [duplicate]

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress