• Welcome to Simple Machines Community Forum. Please login or sign up.
January 21, 2022, 04:42:27 PM

News:

Wondering if this will always be free?  See why free is better.


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.
No good deed goes unpunished
All helpful urges should be circumvented

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.
No good deed goes unpunished
All helpful urges should be circumvented

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

No good deed goes unpunished
All helpful urges should be circumvented


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.
No good deed goes unpunished
All helpful urges should be circumvented

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.
No good deed goes unpunished
All helpful urges should be circumvented

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

rightofatilla

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?

Arantor

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.
No good deed goes unpunished
All helpful urges should be circumvented

rightofatilla

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?

Arantor

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.
No good deed goes unpunished
All helpful urges should be circumvented

rightofatilla

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?

Kindred

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....)
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."

Arantor

I'm absolutely certain this is not a problem you need to worry about.
No good deed goes unpunished
All helpful urges should be circumvented

rightofatilla

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

rightofatilla

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

MrPhil

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

Advertisement: