Menu Close

How to fix – IMG tag does not have an ALT attribute?

Codeamend

Add below codes on your function.php file and fix the image alt attribute missing error.

function code_gravatar_alt($codeGravatar) {
	if (have_comments()) {
		$alt = get_comment_author();
	}
	else {
		$alt = get_the_author_meta('display_name');
	}
	$codeGravatar = str_replace('alt=\'\'', 'alt=\'Avatar for ' . $alt . '\' title=\'Gravatar for ' . $alt . '\'', $codeGravatar);
	return $codeGravatar;
}
add_filter('get_avatar', 'code_gravatar_alt'); 
Posted in WordPress

You can also read...