• I’m new to wordpress and trying to learn my way through from making a theme.
    Right now I am using wp_nav_menu to generate my menu
    My menu consists of pages and categories

    However, the default generation of the menu looks like

    <div id="navi">
    			<div class="menu-primary-container"><ul id="menu-primary" class="menu"><li id="menu-item-14" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-14"><a href="http://localhost/2in1design/intro-2/">Intro</a></li>
    <li id="menu-item-16" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16"><a href="http://localhost/2in1design/category/portfolio/">Portfolio</a></li>
    <li id="menu-item-20" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20"><a href="http://localhost/2in1design/contact/">Contact</a></li>
    <li id="menu-item-15" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-15"><a href="http://localhost/2in1design/category/blog/">Blog</a></li>
    <li id="menu-item-17" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-17"><a href="#">Shop</a></li>
    
    </ul></div>        </div>

    I want to remove all the class and id from
    <li> and <ul>. Have been googling for awhile now. Tried different methods and no luck. Any help would be much appreciated.

    Thank you in advance!

Viewing 9 replies - 1 through 9 (of 9 total)
  • You probably want to keep the menu’s itemID’s and current-page-item indicators.

    So I rewrote it, becoming this:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    It would be much better telling WordPress not to add the classes (instead of removing them afterwards), but I don’t know if that’s possible.

    Why do you want to remove them (out of curiosity)?

    Because it takes bytes. It should be optional. If one only adds pages to the menu, there’s no need to specify the type. Also a class like ‘menu-item’ is not needed because .menu LI does the same.

    Another thing I don’t understand is why the id (menu-item-#ID) is added as a class, while it’s already available as an ID-attribute. If anyone knows a quick way to remove that it’d be nice.

    Here’s the function for removing those classes (put it in functions.php)

    http://pastebin.com/jCsYH9Zr

    It keeps everything with a number, so the menu-item-#ID class stays. I’d like to remove that as well.

    Because it takes bytes.

    Uhhh…. really? Those “bytes” are utterly irrelevant.

    It should be optional.

    Technically, it is. You can write a callback function to output whatever you want.

    You can write a callback function to output whatever you want.

    Thanks for the tip, I hadn’t thought about that. How does one do that? If it’s like an option (instead of forcing/molding it after it has already been generated) I’d be glad to do it that way.

    Every byte counts.

    See the Codex: wp_nav_menu()

    You’ll need to use the walker argument. Creating custom Walker objects exceeds my expertise. 🙂

    Thank you man, I should have looked at that earlier.
    I’ll rewrite it as a walker and post that.

    http://pastebin.com/kz9iSc5y

    There it is. Most of the code comes from WP’s source. This must be the best solution.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘wp_nav_menu remove classes from li’ is closed to new replies.