/ Published in: PHP
Turns Wordpress custom menus into responsive-ready menu that comes with foundation framework. code goes into functions.php
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* http://codex.wordpress.org/Function_Reference/register_nav_menus#Examples */ 'top-bar-l' => 'Left Top Bar', // registers the menu in the WordPress admin menu editor 'top-bar-r' => 'Right Top Bar' )); /* http://codex.wordpress.org/Function_Reference/wp_nav_menu */ // the left top bar function foundation_top_bar_l() { 'container' => false, // remove nav container 'container_class' => 'menu', // class of container 'menu' => '', // menu name 'menu_class' => 'top-bar-menu left', // adding custom nav class 'theme_location' => 'top-bar-l', // where it's located in the theme 'before' => '', // before each link <a> 'after' => '', // after each link </a> 'link_before' => '', // before each link text 'link_after' => '', // after each link text 'depth' => 5, // limit the depth of the nav 'fallback_cb' => false, // fallback function (see below) 'walker' => new top_bar_walker() )); } // end left top bar // the right top bar function foundation_top_bar_r() { 'container' => false, // remove nav container 'container_class' => '', // class of container 'menu' => '', // menu name 'menu_class' => 'top-bar-menu right', // adding custom nav class 'theme_location' => 'top-bar-r', // where it's located in the theme 'before' => '', // before each link <a> 'after' => '', // after each link </a> 'link_before' => '', // before each link text 'link_after' => '', // after each link text 'depth' => 5, // limit the depth of the nav 'fallback_cb' => false, // fallback function (see below) 'walker' => new top_bar_walker() )); } // end right top bar /* Customize the output of menus for Foundation top bar classes */ class top_bar_walker extends Walker_Nav_Menu { function display_element($element, &$children_elements, $max_depth, $depth=0, $args, &$output) { $element->classes[] = ($element->has_children) ? 'has-dropdown' : ''; parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); } function start_el(&$output, $item, $depth, $args) { $item_html = ''; parent::start_el($item_html, $item, $depth, $args); $output .= ($depth == 0) ? '<li class="divider"></li>' : ''; $output .= '<li class="divider"></li>'; } $output .= $item_html; } $output .= "\n<ul class=\"sub-menu dropdown\">\n"; } } // end top bar walker
URL: https://gist.github.com/awshout/3943026