Adding class to gravatar img in wordpress

后端 未结 4 1778
北恋
北恋 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:54

    Another way to do this for future searchers, very simple string manipulation which is probably a bit safer if they change the function in the future e.g. it'll likely always have a 'class'.

        $grvimg = get_avatar('email address', 200);
        $grvimg = explode("class='", $grvimg);
        $grvimg[1] = 'your-class ' . $grvimg[1];
        $grvimg = $grvimg[0] . $grvimg[1];
        echo $grvimg;
    

提交回复
热议问题