How do I set alt tags for avatars?

Started by rightofatilla, March 06, 2013, 02:05:46 PM

Previous topic - Next topic

rightofatilla

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.

mashby

I think at the moment, it's set as alt="". What did you want to set it to?
Always be a little kinder than necessary.
- James M. Barrie

rightofatilla

and while I'm at it, the 'no new posts' and 'redirect board' images need alt tags as well.

rightofatilla

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.

rightofatilla

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!

mashby

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="" />'),
Always be a little kinder than necessary.
- James M. Barrie

rightofatilla

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?

Arantor

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.

mashby

OK, yeah. Go with Arantor's suggestion instead :)
Always be a little kinder than necessary.
- James M. Barrie

rightofatilla

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']? 

Arantor

Because that's their username, not their display name.

rightofatilla

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.

Arantor



rightofatilla

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'.

Arantor

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.

rightofatilla

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.

Arantor

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.

rightofatilla

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.

Kindred

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..
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: