Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need a little help, I'm basically trying to add a custom data attribute to the a tag in all menu items.

So as it stands, I have this:

<a href="/">Home</a>
<a href="/about">About</a>

and I'm aiming to have this:

<a href="#" data-hover="Home">Home</a>
<a href="/about" data-hover="About">About</a>

I've been able to find a little info on extending the Walker class and also found the following question - Adding attributes to <a> link in wp_nav_menu using custom Walker function

I had a look at the linked question/answer but couldn't quite figure out how to change the start_el function to suit my needs without doing it in the core WP files. I've got as far as extending the class:

class My_Walker_Nav_Menu extends Walker_Nav_Menu {

// function start_el(....

}

Any help on adapting this to my needs would be great! Thanks!

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.