The third parameter $size
was introduced in WordPress 4.1. Before that there was only $attr
and $attachment
.
So for this to work before WP 4.1, you need to provide a default value for $size
. Since default for size is thumbnail
, you can use that in your filter hook’s function definition.
So, modify your CODE as follows:
function azu_post_thumbnail_responsive_size($attr, $attachment, $size="thumbnail") {
if ($size === 'az_medium') {
$attr['sizes'] = '(max-width: 639px) 100vw, (max-width: 1023px) 50vw, 334px';
}
else if ($size === 'az_large') {
$attr['sizes'] = '(max-width: 1023px) 100vw, 717px';
}
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'azu_post_thumbnail_responsive_size', 10 , 3);
Now it’ll work for all versions of WordPress.
Note: obviously, any CODE related to the
$size
parameter will not function similarly pre & post WP 4.1. However, at least you’ll not get the error.