【问题标题】:WordPress - remove the width and height attributes on avatarsWordPress - 删除头像的宽度和高度属性
【发布时间】:2014-11-18 13:38:10
【问题描述】:

为什么我的functions.php中的这个过滤器对cmets中的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 );

.

在我的 cmets 模板中,我使用这个 PHP 标签来打印(gr)头像。

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

【问题讨论】:

    标签: php wordpress add-filter


    【解决方案1】:

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

    这是 \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 );
    

    【讨论】:

      猜你喜欢
      • 2012-06-16
      • 2014-12-01
      • 1970-01-01
      • 2023-04-05
      • 2014-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多