Sergey
Sergey

Reputation: 5476

WordPress: How to apply custom CSS class to the root UL using wp_nav_menu()?

I use WordPress 4.1.1 and want to apply custom CSS class to the root ul element. To render my menu I use wp_nav_menu function:

<?php wp_nav_menu(array('menu' => 'top-menu', 'menu_class' => 'my-menu')); ?>

According to the Codex, I use menu_class option to customize ul class. Unfortunately, I have the following markup:

<div class="my-menu"><ul>.....</ul></div>

The root ul element does not have my-menu class.

Upvotes: 0

Views: 162

Answers (1)

johnnyd23
johnnyd23

Reputation: 1705

I like to configure wp_nav_menu() to only output the li elements, allowing me to put any markup I need on the ul

<ul class="my-menu">
    <?php 
        $args = array(
            'menu' => 'top-menu',
            'container' => false, 
            'items_wrap' => '%3$s'
        );
        wp_nav_menu($args); 
    ?>
</ul>

Upvotes: 1

Related Questions