Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: rightofatilla on March 06, 2013, 02:05:46 PM

Title: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 02:05:46 PM
I need to set alt tags for our forum's avatars.  I can't seem to find how to do that.  I know this should be easy functionality, so any help is appreciated.
Title: Re: How do I set alt tags for avatars?
Post by: mashby on March 06, 2013, 02:12:22 PM
I think at the moment, it's set as alt="". What did you want to set it to?
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 02:12:29 PM
and while I'm at it, the 'no new posts' and 'redirect board' images need alt tags as well.
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 02:12:58 PM
Quote from: mashby on March 06, 2013, 02:12:22 PM
I think at the moment, it's set as alt="". What did you want to set it to?

Just the username.
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 02:38:39 PM
I guess I'll make the change myself.  I assume I'll do it in Load.php, in the $memberContext[] array, and just replace the 'alt=""' in the 'image' key, in the 'avatar' key, to alt="' . $profile['member_name'] . '".

Thanks!
Title: Re: How do I set alt tags for avatars?
Post by: mashby on March 06, 2013, 02:47:22 PM
OK, in Sources/Load.php, find this:
'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '<img class="avatar" src="' . (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img class="avatar" src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" />'),


And replace with this:
'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '<img class="avatar" src="' . (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="' . $user_info['username'] . '" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img class="avatar" src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" />'),
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 02:52:01 PM
Quote from: mashby on March 06, 2013, 02:47:22 PM
OK, in Sources/Load.php, find this:
'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '<img class="avatar" src="' . (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img class="avatar" src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" />'),


And replace with this:
'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '<img class="avatar" src="' . (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="' . $user_info['username'] . '" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img class="avatar" src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" />'),


I already changed it to this:


'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '<img class="avatar" src="' . (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="' . $profile['member_name'] . '" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img class="avatar" src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="' . $profile['member_name'] . '" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="' . $profile['member_name'] . '" />'),


Would that not work?
Title: Re: How do I set alt tags for avatars?
Post by: Arantor on March 06, 2013, 02:53:10 PM
I wouldn't use $user_info, that's the details of the currently logged in user. $profile['real_name'] is quite possibly more likely to be right off the top of my head.
Title: Re: How do I set alt tags for avatars?
Post by: mashby on March 06, 2013, 03:02:46 PM
OK, yeah. Go with Arantor's suggestion instead :)
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 03:10:57 PM
Quote from: Arantor on March 06, 2013, 02:53:10 PM
I wouldn't use $user_info, that's the details of the currently logged in user. $profile['real_name'] is quite possibly more likely to be right off the top of my head.

How about $profile['member_name']? 
Title: Re: How do I set alt tags for avatars?
Post by: Arantor on March 06, 2013, 03:13:14 PM
Because that's their username, not their display name.
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 03:30:53 PM
Quote from: Arantor on March 06, 2013, 03:13:14 PM
Because that's their username, not their display name.

Their display name is fine.
Title: Re: How do I set alt tags for avatars?
Post by: Arantor on March 06, 2013, 03:38:48 PM
Then use the code I posted. ;)
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 03:42:02 PM
Quote from: Arantor on March 06, 2013, 03:38:48 PM
Then use the code I posted. ;)

Will do, thanks!
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 03:45:37 PM
Quote from: Arantor on March 06, 2013, 03:38:48 PM
Then use the code I posted. ;)

I just made that change, and now it's not showing.  It was with 'member_name'.
Title: Re: How do I set alt tags for avatars?
Post by: Arantor on March 06, 2013, 03:55:13 PM
It worked for me when I checked the code just now. $profile['real_name'] is even used further up the file in question, if your change is on or around line 1190 (modifications depending), you'll see this on line 1138:
'name' => $profile['real_name'],

And since that's in loadMemberContext, that's where it's getting the main username for posts... so if that's modified you have a mod that's breaking something reasonably fundamental.
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 04:03:39 PM
Quote from: Arantor on March 06, 2013, 03:55:13 PM
It worked for me when I checked the code just now. $profile['real_name'] is even used further up the file in question, if your change is on or around line 1190 (modifications depending), you'll see this on line 1138:
'name' => $profile['real_name'],

And since that's in loadMemberContext, that's where it's getting the main username for posts... so if that's modified you have a mod that's breaking something reasonably fundamental.

No, I'm using a fresh install with no mods.

It is showing in the thread posts, but not the top left.
Title: Re: How do I set alt tags for avatars?
Post by: Arantor on March 06, 2013, 04:06:29 PM
Which isn't set there, it's set somewhere else entirely (in Subs.php, if I remember rightly)

Question, why worry about that? If you're hoping for an SEO boost, no point because that corner avatar doesn't show to search engines... and given that it's next to a "Hello <name>" message it would likely be superfluous.

In fact, if you're doing it for speech readers, it is almost certainly superfluous given its proximity to the actual name entry anyway.
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 04:11:25 PM
Quote from: Arantor on March 06, 2013, 04:06:29 PM
Which isn't set there, it's set somewhere else entirely (in Subs.php, if I remember rightly)

Question, why worry about that? If you're hoping for an SEO boost, no point because that corner avatar doesn't show to search engines... and given that it's next to a "Hello <name>" message it would likely be superfluous.

In fact, if you're doing it for speech readers, it is almost certainly superfluous given its proximity to the actual name entry anyway.

Yeah, I'm just OCD.  I can live with this though.

I need to set the alt tags for the small images.  Any advice before I start hacking away?

By the way, why are these not set?  Who makes the decision to not do simple, fundamental stuff like this?  I know I'm not the only one who is trying to adhere to the search engine guidelines.
Title: Re: How do I set alt tags for avatars?
Post by: Kindred on March 06, 2013, 04:15:02 PM
which small images?
In many cases, it's actually worse to set the alt tags for small display images that server no purpose other than to make it look pretty. After all, the main ideas for alt tags are 1- to tell search engines that this image is important in some way, hence the tag describing the image and 2- to cover for disabled "viewer" capabilities like for the blind reads, which resolves all images as their alt-text equivalent.   In that case, adding alt tags for all the tiny crap pictures actually makes th epage incredibly over crowded..
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 04:17:39 PM
Quote from: Kindred on March 06, 2013, 04:15:02 PM
which small images?
In many cases, it's actually worse to set the alt tags for small display images that server no purpose other than to make it look pretty. After all, the main ideas for alt tags are 1- to tell search engines that this image is important in some way, hence the tag describing the image and 2- to cover for disabled "viewer" capabilities like for the blind reads, which resolves all images as their alt-text equivalent.   In that case, adding alt tags for all the tiny crap pictures actually makes th epage incredibly over crowded..

How do I tell this to Google and Bing, who say images should have alt tags set?  Or, can you refer me to where Google and Bing say to just not worry about this, or it actually is worse?
Title: Re: How do I set alt tags for avatars?
Post by: Arantor on March 06, 2013, 04:18:09 PM
QuoteI need to set the alt tags for the small images.

What small images?

QuoteBy the way, why are these not set?

For the exact reason I outlined. In the case of all the avatars (both the user's own and the per-post avatars), you're explicitly duplicating content that is nearby in the markup. That's not going to endear you to the search engines or visually impaired users for whom it was originally intended anyway.

Try disabling images in your browser and navigate around. If an icon doesn't have a description, it needs one. If it doesn't (like avatars), you don't gain anything by including it.

QuoteWho makes the decision to not do simple, fundamental stuff like this?

Competent people who understand what this stuff actually means and why it is better adhering to the search engine guidelines than shoving it in blindly.
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 04:19:51 PM
Quote from: Arantor on March 06, 2013, 04:18:09 PM
QuoteI need to set the alt tags for the small images.

What small images?

QuoteBy the way, why are these not set?

For the exact reason I outlined. In the case of all the avatars (both the user's own and the per-post avatars), you're explicitly duplicating content that is nearby in the markup. That's not going to endear you to the search engines or visually impaired users for whom it was originally intended anyway.

Try disabling images in your browser and navigate around. If an icon doesn't have a description, it needs one. If it doesn't (like avatars), you don't gain anything by including it.

QuoteWho makes the decision to not do simple, fundamental stuff like this?

Competent people who understand what this stuff actually means and why it is better adhering to the search engine guidelines than shoving it in blindly.

So, when Bing Webmaster Tools, for instance, complains about these not being set, that means it's really OK?
Title: Re: How do I set alt tags for avatars?
Post by: Arantor on March 06, 2013, 04:23:01 PM
Bing Webmaster Tools doesn't check whether it's *relevant* content. It only checks whether there IS content. But no content is better than bad content - and bad content in this case is straight up duplication of other stuff on the page.
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 04:25:49 PM
Quote from: Arantor on March 06, 2013, 04:23:01 PM
Bing Webmaster Tools doesn't check whether it's *relevant* content. It only checks whether there IS content. But no content is better than bad content - and bad content in this case is straight up duplication of other stuff on the page.

So, you are certain this doesn't drag us down with Google and Bing?
Title: Re: How do I set alt tags for avatars?
Post by: Kindred on March 06, 2013, 04:28:43 PM
I have a site, with no tweaks done that has a fine gogole rank and is on page 1 of many searches.

(as for Bing, who cares?    LOL, just kidding,     but I hate bing....)
Title: Re: How do I set alt tags for avatars?
Post by: Arantor on March 06, 2013, 04:30:48 PM
I'm absolutely certain this is not a problem you need to worry about.
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 04:31:03 PM
Quote from: Kindred on March 06, 2013, 04:28:43 PM
I have a site, with no tweaks done that has a fine gogole rank and is on page 1 of many searches.

(as for Bing, who cares?    LOL, just kidding,     but I hate bing....)

haha, I'm with you, but I gotta keep the other folks happy...

If you guys are sure that Google and Bing are OK with it, then ok.....

Our site is number 1 on many searches as well, and it seems like every time I make a little tweak like this, our traffic increases over the next few months...
Title: Re: How do I set alt tags for avatars?
Post by: rightofatilla on March 06, 2013, 04:31:23 PM
Quote from: Arantor on March 06, 2013, 04:30:48 PM
I'm absolutely certain this is not a problem you need to worry about.

Good enough for me.....
Title: Re: How do I set alt tags for avatars?
Post by: MrPhil on March 06, 2013, 05:23:36 PM
Don't forget that only IE shows the alt= text as a tooltip (if that's what you're looking for). alt= should be information for screen readers and search engines and other non-graphical displays. Don't use it for trivial images like bullets, spacers, and such doodads. Use title= to display a tooltip when you hover over an image (or any other element) (it will override the alt= text on IE).