WordPress.org

Ready to get started?Download WordPress

Forums

WP Menu walker function to display parent description and wrap parent in own div (1 post)

  1. Luke Etheridge
    Member
    Posted 1 year ago #

    Hi guys,

    Anyone know how to write a custom walker function for wp_nav_menu that will...

    1) Display the item description for parent items only.

    2) Wrap the parent item (title, link and description) in it's own div only if it has children.

    (I've simplified the div's, li's and ul's to have no classes)

    <div>
      <ul>
    
        <!-- Parent With Children -->
        <li>
          <div class="parent">
            <a>Parent Item</a>
            <span class="desc">Description</span>
          </div>
            <ul>
              <li><a>Child Item</a></li>
              <li><a>Child Item</a></li>
              <li><a>Child Item</a></li>
              <li><a>Child Item</a></li>
              <li><a>Child Item</a></li>
            </ul>
        </li>
    
        <!-- Parent Without Children -->
        <li>
          <a>Parent Item</a>
          <span class="desc">Description</span>
        </li>
    
      </ul>
    </div>

    Judging by the flexibility of the walker function I'm pretty sure this shouldn't be hard at all but I'm not a PHP wiz by any means. Thanks in advance.

    Luke

Topic Closed

This topic has been closed to new replies.

About this Topic