Adding class to gravatar img in wordpress

后端 未结 4 1775
北恋
北恋 2021-02-08 13:26

I\'ve been trying to use get_avatar to display the author\'s gravatar under each post in wordpress template with applied class but I couldn`t find a way to add

4条回答
  •  梦谈多话
    2021-02-08 13:45

    If @Ryan answer (marked as solution) does'nt work for you, try to change

    add_filter('get_avatar','add_gravatar_class');
    
    function add_gravatar_class($class) {
        $class = str_replace("class='avatar", "class='avatar pic-2", $class);
        return $class;
    }
    

    into

    add_filter('get_avatar','add_gravatar_class');
    
    function add_gravatar_class($class) {
        $class = str_replace('class="avatar', 'class="avatar pic-2', $class);
        return $class;
    }
    

    This start's work for me after replace " with '.

    Sorry that I didn't write this as a comment to that answer, but I don't have 50 reputation to comment other posts.

提交回复
热议问题