How to create data attribute containing post id in main nav?
-
Hi all,
Was wondering how I would go about adding a data attribute on to each of my main nav list items containing the post ID? Is there a param I can use?
At the moment I’m using the following code:
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
Which outputs li’s to look like:
<li class="page_item page-item-4"><a href="#">Lunch Menu</a></li>
Basically I would like them to look something like:
<li class="page_item page-item-4" data-id="4"><a href="#">Lunch Menu</a></li>
So I can access the ID in order to access the data for that post
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘How to create data attribute containing post id in main nav?’ is closed to new replies.