Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created a custom menu to replace my li with td markers. However, I need to be able to add some custom tags through the wordpress menu. How do I do so? Is there something I can add to my mytag_nav_menu section to allow me to add custom csstags from the wordpress menu?

My functions code located inside functions.php:

function mytag_nav_menu($args = '', $mytag = 'td') {
        $defaults = array(
            'echo' => 1

        $r = wp_parse_args($args, $defaults);
        $args = $args.'&echo=0';
        $oldtags = Array('<li','</li>');
        $newtags = Array('<'.$mytag.' class="center"','</'.$mytag.'>');
        $mynav = str_replace($oldtags, $newtags, wp_nav_menu($args));
        $output= preg_replace('/<a/', '<a class="nav"', $mynav, 12);
        if ( $r['echo'] )
            echo $output;
            return $output;

My function call in the header located in header.php:

<?php mytag_nav_menu(array('theme_location' => 'header-menu',
'items_wrap' => '<tr>%3$2</tr>',

Explanation of what I want to do:

  1. Go into Wordpress admin
  2. Go to Appearance/Menus
  3. Click on a menu item, click on the drop down arrow
  4. Add to CSSClasses (Optional)
  5. Save the menu 6 Have the classes show up

Result should be:

<td class="center **MYCUSTOMCSSADDEDFROMMENU**" id="menu-item-BLAHEXAMPLE">
<a class="nav" href="lol.html">News</a>

Can anyone explain to me what I can add to my mytag_nav_menu to let those custom classes show up but still edit the tags as below?

If this is not clear, please let me know.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.