Archived

This topic is now archived and is closed to further replies.

  • 0

custom menu class

Question

Posted · Report post

Hi,

 

i want to change the class which is given to a menu by default. I think it is part of wp_nav_menu - but i dont know where to find it in pagelines. Anyway i would prefer to make the change in the function.php (if possible?)

 

I need it for a custom WP menu in the sidebar - now the html appears like this:

<div class="widget-pad">   
     <div class="menu-test-container">
           <ul id="menu-test" class="menu">
                ....

 

 

I want to change it into that:

<div class="widget-pad">
    <div class="menu-test-container">
          <ul id="menu-test" class="custom">
                ....

 

 

Can this class be changed in the functions.php?

Share this post


Link to post
Share on other sites

5 answers to this question

Posted · Report post

Hi,

 

What do you need to get into functions.php? Couldn't you use the functions.php found in the PageLines Customize plugin or in a child theme?

Share this post


Link to post
Share on other sites

Posted · Report post

There is a snippet in the nav-menu-template.php on line 136:

 

function wp_nav_menu( $args = array() ) {
    static $menu_id_slugs = array();

    $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'nav nav-tabs nav-stacked', 'menu_id' => '',
    'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    'depth' => 0, 'walker' => '', 'theme_location' => '' );

 

 

I replaced the default Wordpress menu class to a class provided by bootstrap:

 

'nav nav-tabs nav-stacked'

 

Now i want to move this code into the functions.php to make it update save.

Share this post


Link to post
Share on other sites

Posted · Report post

Hi,

 

What you're referring to is the standard Wordpress Custom Menu widget, when you name your menu, that name is added as a class to that widget, see my images below for an example.

 

1. http://d.pr/i/cFPH

2. http://d.pr/i/Cpu9

3. http://d.pr/i/lcdA

 

As you can see the HTML looks like this:

<li id="nav_menu-2" class="widget_nav_menu widget fix">
<div class="widget-pad">
<h3 class="widget-title">Menu</h3>
<div class="menu-this-is-a-menu-container">
...

If this suggestion isn't what you're looking for then you will need to ask this question on the Wordpress support forums, as this is a Wordpress widget and not related to PageLines.

Share this post


Link to post
Share on other sites

Posted · Report post

From the docs at: http://codex.wordpress.org/Function_Reference/wp_nav_menu

 

you can use the filter wp_nav_menu_args

 

 


 

function my_wp_nav_menu_args( $args = '' )
{
	$args['container'] = false;
	return $args;
} // function

add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );

and change it to do what you want

Share this post


Link to post
Share on other sites

Posted · Report post

Your suggestions lead to aply a class to single menu-items. I want to apply custom css to a the entire ul. Therefore I changed the default wp class name in the nav-menu-template.php and it works fine.
I replaced 'menu' with 'nav nav-tabs nav stacked' and pagelines applies the bootstrap design to the standard Wordpress Widget Menu, which is a big deal for me.

 

But i need to get it into the functions.php...  and yes, you are right - thats a Wordpress question at least. ;-)

Share this post


Link to post
Share on other sites