Skip to main content

set default menu UL css code wordpress

<?php

 $defaults = array(
    'menu_class'      => 'menu',
    'items_wrap'      => '<ul id="%1$s" class="navigation clearfix">%3$s</ul>',
);

wp_nav_menu( $defaults );

?>


<?php
                     wp_nav_menu( array(
                        'theme_location' => 'primary',
                        'menu_class'     => 'nav side-menu',
                     ) );
                ?>


/* Function to change sub-menu class Starts here */
function change_submenu_class($menu) { 
  $menu = preg_replace('/ class="sub-menu"/','/ class="nav child_menu" /',$menu); 
  return $menu; 

add_filter('wp_nav_menu','change_submenu_class'); 
/* Function to change sub-menu class Ends here */


 /*Function to add div around submenu ul starts here*/

class WPSE_78121_Sublevel_Walker extends Walker_Nav_Menu
{
    function start_lvl( &$output, $depth = 0, $args = array() ) {
        $indent = str_repeat("\t", $depth);
        $output .= "\n$indent<div class='submenu-wrapper submenu-wrapper-topbottom'><div class='submenu-inner  submenu-inner-topbottom'><ul class='sub-menu'>\n";
    }
    function end_lvl( &$output, $depth = 0, $args = array() ) {
        $indent = str_repeat("\t", $depth);
        $output .= "$indent</ul></div></div>\n";
    }
}

<?php
                                        /******in header used this for menu***/
                                        wp_nav_menu( array(
                                            'menu'              => 'Main Menu',
                                            'depth'             => 2,
                                            'container'         => '',
                                            'container_class'   => '',
                                            'container_id'      => '',
                                            'menu_class'        => 'nav navbar-nav navbar-right',
                                            'menu_id'           => 'main_navigation',   
                                            'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
                                            'walker'            => new WPSE_78121_Sublevel_Walker
                                            )
                                        );
                                    ?>
 /*Function to add div around submenu ul ends here*/

Comments

Popular posts from this blog

add custom post type

/**  *  * add custom post type  *  */ function my_custom_post_product() {   $labels = array(     'name'               => _x( 'Products', 'post type general name' ),     'singular_name'      => _x( 'Product', 'post type singular name' ),     'add_new'            => _x( 'Add New', 'book' ),     'add_new_item'       => __( 'Add New Product' ),     'edit_item'          => __( 'Edit Product' ),     'new_item'           => __( 'New Product' ),     'all_items'          => __( 'All Products' ),     'vi...

Toolset conditional

[wpv- if evaluate= "'[wpv-current-user info='id']' = '[wpv-post-author format='meta' meta='ID']' OR '[wpv-current-user info='role']' = 'administrator'" ]      //the content you want to hide goes here [/wpv- if ]