• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1664
  • Last Modified:

Wordpress - How Can I Add Alt Tags To Menu Links?

I need to include an 'alt' tag in my wordpress menu links.

Right now, the menu links include the title tag, but not the alt tag.

I'd like the alt tag to include the same thing as the title tag.

I have this in my menu links:

<a title="Home" href="http://www.mysite.com/">Home</a>

but need this:

<a title="Home" alt="Home" href="http://www.mysite.com/">Home</a>

Suggestions? Seems like there should be something I could add to my functions.php to do this, but I have no idea what.

Thanks for any help!

Chris
0
St_Aug_Beach_Bum
Asked:
St_Aug_Beach_Bum
  • 3
  • 2
  • 2
2 Solutions
 
Jason C. LevineNo oneCommented:
Why do you want alt in the <a> tag?  It's not valid there, which is why title is used.  If you add it, you will break HTML validation...

ref: http://www.w3.org/TR/html5/text-level-semantics.html#the-a-element
0
 
St_Aug_Beach_BumAuthor Commented:
Ha, that's funny - I had a feeling someone would ask 'why do you want to do that!'.

I considered including the answer in the question, but figured I didn't really need to get into the 'why', just the 'what'.

But since you asked....

Google lists my site with sitelinks below the main page.

However, the sitelinks are not the main links it should be using. It's using some that are actually second and third level category links.

On Google's sitelinks page:

https://support.google.com/webmasters/answer/47334?hl=en 

they say that to help their algo pick out the right links -  "make sure you use anchor text and alt text that's informative,..."

Interesting, eh? But that's what it says.... so I'd like to try it and see if it makes a difference,

Chris
0
 
Tom BeckCommented:
What Google means...

Anchor text:

<a href="http://somedomain.com">Anchor Text</a>

Alt text:

<a href="http://somedomain.com"><img src="http://somedomain.com/img.jpg" alt="This link text is informative" /></a>
0
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
St_Aug_Beach_BumAuthor Commented:
So you're saying they mean "or", not what they have, which is "and"...
0
 
Tom BeckCommented:
"And" is semantically correct if you have multiple links on the page where some are text links and some are image links. I don't think Google would knowingly suggest that you put alt attributes in anchors.
0
 
Jason C. LevineNo oneCommented:
Correct.  Google is telling you to use good anchor text between your <a> and </a> Text links or if you are using linked images, to use alt text.  They wouldn't tell you to write invalid HTML.  

That being said, you might have to hack the core (bad) or disable the internal menu system and add your own to header.php to do what you propose to do.  I don't see a way to do it via a filter.
0
 
St_Aug_Beach_BumAuthor Commented:
Thank you both.

Well, I've added a title text to the anchors, which I didn't have before. I don't know if that will affect anything, but I'll watch and wait (without adding alt) and see if that helps at all. If not, I'll go back to the drawing board.

Thanks goes to both of you,

Chris
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now