WordPress - 删除头像上的宽度和高度属性


WordPress - remove the width and height attributes on avatars

为什么我的函数中的过滤器.php不适用于注释中的get_avatar()函数?

// Remove height/width attributes on avatar img tags.
function myscript_remove_dimensions_avatars( $avatar ) {
    $avatar = preg_replace( '/(width|height)='"'d*'"'s/', "", $avatar );
    return $avatar;
}
add_filter( 'get_avatar', 'myscript_remove_dimensions_avatars', 10 );

.

在我的评论模板中,我使用此PHP标签来打印(gr)头像。

<?php echo get_avatar( $comment, 96 ); ?>

找到了解决方案,它有点小差异,但它有效。 :)

这是 ''d* 部分附近的双引号与单引号。

// Remove height/width attributes on avatar img tags.
function myscript_remove_dimensions_avatars( $avatar ) {
    $avatar = preg_replace( "/(width|height)='''d*'''s/", "", $avatar );
    return $avatar;
}
add_filter( 'get_avatar', 'myscript_remove_dimensions_avatars', 10 );