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 have a WordPress template (I'm using Foundation as a base and https://github.com/olefredrik/foundationpress/ as a starter theme) I'm trying to build and I can't seem to figure out how to hook into the menu that WordPress outputs and add a custom attribute to that menu's <li> tags. The current menu outputs like this:

<ul id="menu-main-menu-1" class="top-bar-menu right">
<li class="divider"></li>
<li class="menu-item "><a href="#home">Home</a></li>
<li class="divider"></li>
<li class="menu-item"><a href="#about">About</a></li>
<li class="divider"></li>
<li class="menu-item"><a href="#work">My Work</a></li>
<li class="divider"></li>
<li class="menu-item"><a href="#contact">Contact</a></li>
</ul>

(Those links are just there for sample)

I need WordPress to automatically add the following attribute to the <li> tags: data-magellan-arrival="[target]".

[Target] needs to automatically be populated by the page_ID that the menu item corresponds to. So for example, let's say that first's <li><a href="">[PAGE]</a></li> link is Home and Home's page_ID is "21" (example). I would need data-magellan-arrival="[target]" inside of <li> to be set to data-magellan-arrival="21".

So it would look like: <li class="menu-item" data-magellan-arrival="21"><a href="">[PAGE]</a></li>

I'll be honest with you, I'm not that great at PHP just yet and WordPress filters/hooks much less. Hoping someone can point me in the right direction or show me how to do it.

Thanks!

share|improve this question

1 Answer 1

This looks like it would get you pointed in the right direction:

http://stackoverflow.com/questions/6215797/wordpress-post-id-in-wp-nav-menu

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.