在Wordpress中为Gravatar img添加类 [英] Adding class to gravatar img in wordpress
问题描述
我一直在尝试使用get_avatar在应用模板的wordpress模板中的每个帖子下显示作者的头像,但是我找不到方法将class ="pic-2"添加到图像图像代码,甚至将图像高度和宽度分别更改为100px和77px
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 class="pic-2" to gravatar image code or even changing gravatar heigth and width to 100px and 77px respectively
<?php echo get_avatar( get_the_author_meta('ID'), 32 ); ?>
任何帮手??
推荐答案
我认为处理此问题的最佳方法是使用过滤器,而不是乔治建议的使用jQuery.您只需将其添加到主题的 functions.php 文件中即可.
I think the best way to handle this would be to use a filter, rather than using jQuery as George suggests. You would simply add this to your theme's functions.php file.
add_filter('get_avatar','add_gravatar_class');
function add_gravatar_class($class) {
$class = str_replace("class='avatar", "class='avatar pic-2", $class);
return $class;
}
*请注意,我尚未对此进行测试,但相信它会起作用.有关更多信息,请参见此线程.
*Note, I've not tested this, but believe it will work. See this thread for more info.
这篇关于在Wordpress中为Gravatar img添加类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!