admin管理员组文章数量:1335380
One visitor commented on one of my post as a guest. Now, i want to change avatar of this comment using comment ID. Comment ID of the comment is 1092. How can i change avatar of the comment using comment id?
Actually i want to change avatar for couple of comments.
Any help would be greatly appreciated.
One visitor commented on one of my post as a guest. Now, i want to change avatar of this comment using comment ID. Comment ID of the comment is 1092. How can i change avatar of the comment using comment id?
Actually i want to change avatar for couple of comments.
Any help would be greatly appreciated.
Share Improve this question asked Jul 23, 2020 at 4:59 DivyangDivyang 132 bronze badges1 Answer
Reset to default 1You can use pre_get_avatar
filter to manipulate comment avatar html and stop WP from getting a default avatar for the comment.
Passing a non-null value will effectively short-circuit get_avatar(), passing the value through the ‘get_avatar’ filter and returning early.
E.g.
add_filter( 'pre_get_avatar', 'my_filter_pre_get_avatar', 10, 3 );
function my_filter_pre_get_avatar( $avatar_html, $id_or_email, $args ) {
if ( is_a( $id_or_email, 'WP_Comment' ) ) {
// Add more cases with elseif or use a switch statement here
if ( '1092' === $id_or_email->comment_ID ) {
// set avatar to whatever html you want
$avatar_html = '<img class="avatar" src="" alt="Custom avatar">';
}
}
return $avatar_html;
}
Use this in your theme's functions.php
file or in a custom plugin.
本文标签: How to change avatar of the comment author using comment ID
版权声明:本文标题:How to change avatar of the comment author using comment ID? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742236176a2438121.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论