WordPress.org

Ready to get started?Download WordPress

Ideas

Make it easier to use definition lists with wp_nav_menu

  1. jettrush
    Member

    I may be missing something but I noticed something that I think can be improved. Currently, it looks like if a developer wants to output a list using wp_nav_menu, they are stuck with unordered lists like this:

    <ul>
         <li></li>
         <li></li>
    </ul>

    What if the developer thinks that the appropriate markup should be a definition list:

    <dl>
         <dt><dt>
         <dd></dd>
         <dd></dd>
    </dl>

    Since there are only 3 kinds of lists in HTML, it seems that wp_nav_menu ought to have built-in support for <dl> rather than relying on developers to write custom walker classes each time.

    Posted: 3 years ago #
  2. davidpaulsson
    Member

    I'd +1 this if I could. Or did I just do that? Nvm, good idea. You have my full support.

    Posted: 2 years ago #
  3. MayerRubin
    Member

    I know its a bit late, but maybe this will help the next person with the same problem.

    I got it to do what you wanted by a combination of function arguments (echo and items_wrap) and processing the output of wp_nav_menu() using the PHP function str_replace().

    $args = array(
      'echo' => false,
      'items_wrap' => '<dl id="%1$s" class="%2$s myclass">%3$s</dl>',
    );
    $subject = wp_nav_menu( $args ); 
    
    $search  = array('<ul', '</ul>', '<li', '</li>');
    $replace = array('<dl', '</dl>', '<dd', '</dd>');
    echo str_replace($search, $replace, $subject);

    You can replace the <ul> tag either in the items_wrap argument or in the str_replace().

    Posted: 2 years ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    6 Votes
  • Status

    This idea is under consideration