QNimate

  • CoursesVideos
  • WP PremiumPlugins
  • DemosLab
  • Home
  • QIdea
  • QTrack
Home Carbon Ads WordPress Remove Avatar from Comments Only

WordPress Remove Avatar from Comments Only

To disable WordPress from displaying avatars in comments WordPress provides a option in Settings ยป Discussion to disable avatars.

disable-avatar

But the issue is that this option disables avatar throughout the website. Therefore avatar on author info box is not displayed.

So I have written a code snippet which disables avatar only on comments template. This code overrides the above option too.

function disable_comment_avatar($avatar, $id_or_email, $size, $default, $alt)
{
    global $in_comment_loop;

    if(isset($in_comment_loop))
    {
        if($in_comment_loop == true)
        {
            return "<img alt='{$alt}' src='' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
        }
        else
        {
            return $avatar;
        }
    }
    else
    {
        return $avatar;
    }
}

add_filter("get_avatar" , "disable_comment_avatar" , 1, 5);

You can inject this code as WordPress plugin or else you can paste this code in your theme’s functions.php file.

This code interpret get_avatar functions’s return value. This function is used by WordPress core’s comment template to retrieve avatar’s HTML i.e., img tag with src attribute.

Mar 1, 2015Narayan Prusty
GMail Removes "class", "id" and Styles from HTML EMailWordPress $notoptions Array
Comments: 2
  1. Ahmed
    6 years ago

    ‘avatar_size’ => 0

    ReplyCancel
    • Fabian
      6 years ago

      very simple solution. At first I thought setting the avatar image to 0 was going to generate the img tag but that wasnt the case at all. No need for the code above

      ReplyCancel

Leave a Reply Cancel reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Narayan Prusty

I am a software engineer specialising in Blockchain, DevOps and Go/JavaScript. This is my personal blog where I write about things that I learn and feel interesting to share.

8 years ago 2 Comments WordPress
Share this
0
GooglePlus
0
Facebook
0
Twitter
0
Linkedin
Related Articles
  • Change WordPress Default Avatar
  • Creating Custom WordPress Shortcodes using PHP
  • Changing WordPress Admin Footer Text
  • Advanced Guidelines To WordPress Theme Development
  • Anti Adblock Plugin for WordPress
Our Sponsor
My Books

2014 - 2015 © QNimate
All tutorials MIT license