Skip to main content
added 990 characters in body
Source Link
Adam
  • 21
  • 3

Is there any way to display template name (or page-template.php filename) in each menu items' class? Maybe using wp_nav_menu walker?

Specifically, I'm using standard menu call:

wp_nav_menu( array( 'menu' => 3, 'container' => false )

Which gives me:

<div class="menu-wrap">
<ul id="menu-menu" class="menu">
<li id="menu-item-979" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-979"><a href="#">Homepage</a></li>
<li id="menu-item-844" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-844"><a href="#">Subpage</a></li>
</ul>
</div>

And if I have template names Homepage and Subpage, I'd like to get the same, but with template name classes:

<div class="menu-wrap">
<ul id="menu-menu" class="menu">
<li id="menu-item-979" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-979 Homepage"><a href="#">Homepage</a></li>
<li id="menu-item-844" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-844 Subpage"><a href="#">Subpage</a></li>
</ul>
</div>

Thanks!

Is there any way to display template name (or page-template.php filename) in each menu items' class? Maybe using wp_nav_menu walker?

Thanks!

Is there any way to display template name (or page-template.php filename) in each menu items' class? Maybe using wp_nav_menu walker?

Specifically, I'm using standard menu call:

wp_nav_menu( array( 'menu' => 3, 'container' => false )

Which gives me:

<div class="menu-wrap">
<ul id="menu-menu" class="menu">
<li id="menu-item-979" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-979"><a href="#">Homepage</a></li>
<li id="menu-item-844" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-844"><a href="#">Subpage</a></li>
</ul>
</div>

And if I have template names Homepage and Subpage, I'd like to get the same, but with template name classes:

<div class="menu-wrap">
<ul id="menu-menu" class="menu">
<li id="menu-item-979" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-979 Homepage"><a href="#">Homepage</a></li>
<li id="menu-item-844" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-844 Subpage"><a href="#">Subpage</a></li>
</ul>
</div>

Thanks!

Source Link
Adam
  • 21
  • 3

wp_nav_menu - page template name as item class

Is there any way to display template name (or page-template.php filename) in each menu items' class? Maybe using wp_nav_menu walker?

Thanks!