• My function to add alt and title attributes to the avatar image no longer works after activating the plugin.

    function replace_content($text) { 
      $alt = get_the_author_meta( 'display_name' ); 
      $text = str_replace('alt=\'\'', 'alt=\''.$alt.'\' title=\''.$alt.'\'',$text);
      return $text; 
     } 
     add_filter('get_avatar','replace_content'); 

    Any idea how I can add title and alt to uploaded avatar images?

Viewing 1 replies (of 1 total)
  • greencode

    (@greencode)

    I use this one that I found at bloggerpilot and it seems to work with the latest version.

    // Add alt tag to WordPress Gravatar images
    function bloggerpilot_gravatar_alt($bloggerpilotGravatar) {
    	if (have_comments()) {
    		$alt = get_comment_author();
    	}
    	else {
    		$alt = get_the_author_meta('display_name');
    	}
    	$bloggerpilotGravatar = str_replace('alt=\'\'', 'alt=\'Avatar for ' . $alt . '\'', $bloggerpilotGravatar);
    	return $bloggerpilotGravatar;
    }
    add_filter('get_avatar', 'bloggerpilot_gravatar_alt');
Viewing 1 replies (of 1 total)
  • The topic ‘Add Alt and Title to images’ is closed to new replies.