Wordpress Custom Navigation Menus - wordpress

Hi i have the following navigation menus from html css template. I want to change it in wordpress navigation. But CSS doesnot work there. How can i save the css without losing its features.
<!--Header-->
<header class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a id="lgo" class="pull-left" href="index.html"><H1>Global BizVisions, LLC</h1></a>
<div class="nav-collapse collapse pull-right">
<ul class="nav">
<li class="active">Home</li>
<li>About Us</li>
<li>Services</li>
<li>Portfolio</li>
<li class="dropdown">
Pages <i class="icon-angle-down"></i>
<ul class="dropdown-menu">
<li>Career</li>
<li>Blog Single</li>
<li>FAQ</li>
<li>Pricing</li>
<li>404</li>
<li>Typography</li>
<li>Registration</li>
<li class="divider"></li>
<li>Privacy Policy</li>
<li>Terms of Use</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
<li class="login">
<a data-toggle="modal" href="#loginForm"><i class="icon-lock"></i></a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</header>
<!-- /header -->
I did is like this:
<!--Header-->
<header class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<h1>Global BizVisions, LLC</h1>
<div class="nav-collapse collapse pull-right">
<ul>
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'nav' ) ); ?>
<ul>
</div><!--/.nav-collapse -->
</div>
</div>
</header>
<!-- /header -->
and what are the things i need to change in functions.php or other.
Thanks in advance

you need create a walker in your functions.php look:
add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
function special_nav_class($classes, $item){
if( in_array('current-menu-item', $classes) ){
$classes[] = 'active ';
}
return $classes;
}
class My_Custom_Nav_Walker extends Walker_Nav_Menu {
function start_lvl(&$output, $depth = 0, $args = array()) {
$output .= "\n<ul class=\"dropdown-menu\">\n";
}
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
$item_html = '';
parent::start_el($item_html, $item, $depth, $args);
if ( $item->is_dropdown && $depth === 0 ) {
$item_html = str_replace( '<a', '<a class="dropdown-toggle" data-toggle="dropdown"', $item_html );
$item_html = str_replace( '</a>', ' <b class="caret"></b></a>', $item_html );
}
$output .= $item_html;
}
function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) {
if ( $element->current )
$element->classes[] = 'active';
$element->is_dropdown = !empty( $children_elements[$element->ID] );
if ( $element->is_dropdown ) {
if ( $depth === 0 ) {
$element->classes[] = 'dropdown';
} elseif ( $depth === 1 ) {
// Extra level of dropdown menu,
// as seen in http://twitter.github.com/bootstrap/components.html#dropdowns
$element->classes[] = 'dropdown-submenu';
}
}
parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
}
}
in your header.php (if your menu location is header) at the div .navbar-collapse:
erase the ul tag.
the ul is created in the wp_nav_menu:
<?php wp_nav_menu(array(
'theme_location' => 'nav_social',
'container' => false,
'walker' => new My_Custom_Nav_Walker(),
'items_wrap' => '<ul id="your_nav" class="navbar-right"></li>%3$s</ul>'
)
); ?>
remember you need create the menu on the functions.php
function register_my_menus(){
register_nav_menus(array(
'your_nav' => __('your_nav', 'siddharta naranjo')));}add_action('init','register_my_menus');

well
1- Go to wp-admin then
Apperance=>menu
2- create a menu
$nav_menu= array(
'theme_location' => '',
'menu' => 'here menu name',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'sticky',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $nav_menu);
I think it will work out fine for you

Related

how can i prepare menu (arrays) for this code

I am learning wordpress together with bootstrap and i don't kno how to prepare menu for following code :
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav nav-dropdown nav-right" data-app-modern-menu="true">
<li class="nav-item"><a class="nav-link link text-black display-4" href="">Item 1</a></li> <li class="nav-item"><a class="nav-link link text-black display-4" href="">Item 2</a></li>
<li class="nav-item"><a class="nav-link link text-black display-4" href="">Item 3</a></li>
<li class="nav-item"><a class="nav-link link text-black display-4" href="">Item 4</a></li>
</ul> </div>
for this code i am using
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<?php
wp_nav_menu(
array(
'menu' => 'primarym',
'container' => 'ul',
'container_class' => 'navbar-nav nav-dropdown nav-right',
'menu_class' => 'menu',
'menu_id' => 'primary-menu',
'echo' => true,
)
); ?>
</div>
which is not working in my templates, can anyone help me.
No need to create custom walker. Just use additional argument and set the filters for nav_menu_css_class and nav_menu_link_attributes.
Please check below which help you.
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<?php
wp_nav_menu(
array(
'menu' => 'primarym',
'container' => 'ul',
'container_class' => '',
'menu_class' => 'navbar-nav nav-dropdown nav-right',
'menu_id' => 'primary-menu',
'add_li_class' => 'nav-item',
'echo' => true,
)
); ?>
</div>
Notice the new 'add_li_class' argument.
And set the filters on functions.php
function add_additional_class_in_li($classes, $item, $args) {
if(isset($args->add_li_class)) {
$classes[] = $args->add_li_class;
}
return $classes;
}
add_filter('nav_menu_css_class', 'add_additional_class_in_li', 1, 3);
function add_additional_class_in_ancher($atts) {
$atts['class'] = "nav-link link text-black display-4";
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'add_additional_class_in_ancher');
You're close with your function, just keep in mind that container is for the menu's container (in your case, the div tag) and menu is for the menu itself (in your case, the ul tag).
For those two elements, you'll have to set your arguments to:
wp_nav_menu(
array(
'menu' => 'primarym', // or the id of the menu (you could otherwise use theme_location)
'container' => 'div',
'container_id' => 'navbarSupportedContent',
'container_class' => 'collapse navbar-collapse',
'menu_class' => 'navbar-nav nav-dropdown nav-right',
'items_wrap' => '<ul class="%2$s" data-app-modern-menu="true">%3$s</ul>',
'walker' => new My_Walker(),
)
);
You'll notice that there's a new walker argument, without which you won't be able to display the menu element itself (li and a tags) the way you want.
A walker is a core class used to implement an HTML list of nav menu items and here's how you could use it for your example :
class My_Walker extends Walker_Nav_Menu {
function start_lvl( &$output, $depth, $args ) {
}
function start_el( &$output, $item, $depth, $args ) {
// $output : var returned at the end of the walker
// $item : information about the current item
$output .= sprintf(
'<li class="nav-item"><a class="nav-link link text-black display-4" href="%1$s">%2$s',
$item->url,
$item->title
);
}
function end_el( &$output, $item, $depth, $args ) {
// $output : var returned at the end of the walker
$output .= '</a></li>';
}
function end_lvl( &$output, $depth, $args ) {
}
}

Mega menu WordPress walker

Here is my menu structure, how I build a mega menu walker, how I do this ?
<nav>
<ul class="main-nav navbar-right">
<li class="active dropdown">Home
<div class="sub-menu">
<ul class="home">
<li>Home</li>
<li><a class="last" href="index-2.html">Home2</a></li>
</ul>
</div>
</li>
<li class="dropdown">Pages
<div class="mega-menu pages">
<span class="mega-menu-list">
Blog1
Blog2
Blog3
</span>
<span class="mega-menu-list">
Single Blog 1
Single Blog 2
Single Blog 3
Single Blog 4
</span>
<span class="mega-menu-list">
404 Page
Contact Us
</span>
</div>
</li>
<li class="dropdown">Sport</li>
<li>Travel</li>
<li>Lifestyle</li>
<li>Tech</li>
<li><a href=">Contact Us</a></li>
</ul>
</nav>
You can put Your menu structure HTML in this code.
/* Drop Down Menu */
class ik_walker extends Walker_Nav_Menu{
function start_lvl(&$output, $depth) {
if($depth == 0){
$output .= 'HTML Start Here for Parent Menu
';
}
if($depth == 1){
$output .= '<ul class="sub-child"> Start Here for child Menu';
}
}
function end_lvl(&$output, $depth) {
if($depth == 0){
$output .= 'End For Parent Menu
';
}
if($depth == 1){
$output .= '</ul> End for child';
}
}
}
and Use this function in Menu Like this.
if ( has_nav_menu( 'primary' ) ) :
wp_nav_menu( array(
'theme_location' => 'primary',
'menu_class' => 'horizontal_links navigations',
'container' => '',
'depth' => 3,
'walker' => new ik_walker()
) );
endif;

Register Custom menu in wordpress

How to register this menu in wordpress dynamically ?
i'am having problem to dynamic menu in wordpress
<nav id="nav">
<ul>
<li>Division
<ul class="dropotron dropotron-level-0 center" style="-moz-user-select: none; position: absolute; z-index: 1000; left: 184.767px; top: 29px; opacity: 1; display: none;">
<li ><a style="display: block;" href="real-estate.html">Real Estate</a></li>
<li><a style="display: block;" href="waterpump.html">Water Pump</a></li>
<li ><a style="display: block;" href="fmcg.html">FMCG</a></li>
<li ><a style="display: block;" href="infrastructure.html">Infrastructure Project</a></li>
</ul>
</li>
<li >About Us</li>
<li class="break">Career</li>
<li >Contact Us</li>
</ul>
</nav>
Thanks
i'm not sure i'm fully understand what you'r meant when you say 'register this menu in wordpress dynamically', but if you meant to register custom menu and display it so follow this:
put this code on the 'functions.php' file: (if you are not using a theme of your own then create a child theme if you didn't already)
function register_your_menu() {
register_nav_menu('your-menu-location',__( 'Your Menu Description' ));
}
add_action( 'init', 'register_your_menu' );
*register your new menu - it will display the new menu on the admin panel so set it as you like.
put this code on the place you want the menu to appear on the theme and customize the '$defaults' settings as you like (you can find more info here: http://codex.wordpress.org/Function_Reference/wp_nav_menu):
if ( has_nav_menu( 'your-menu-location' ) ) {
$defaults = array(
'theme_location' => 'your-menu-location',
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'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' => ''
);
wp_nav_menu( $defaults );
}

Edit Top Navigation Woocommerce

I have an online store developed in Wordpress/WooCommerce and I need to add some flags, in top navigation.
In header.php I saw that that section is called by woo_top() function, but I don't find it.
Please help me to find this function or how to add some code in top navigation.
// Hook In
add_action( 'woo_top', 'woo_bootstrapped_nav' );
// Our hooked in Function
function woo_bootstrapped_nav() { ?>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<?php bloginfo( 'name' ); ?>
<?php
$args = array(
'theme_location' => 'top-bar',
'depth' => 2,
'container' => 'div',
'container_class' => 'nav-collapse collapse pull-left',
'menu_class' => 'nav',
'walker' => new Bootstrap_Walker_Nav_Menu()
);
wp_nav_menu($args);
?>
<ul class="nav secondary-nav pull-right">
<li class="dropdown"> <?php echo do_shortcode('[fblike style="button_count" width="90" float="left"][google_plusone size="medium" float="left" annotation="bubble"][twitter_follow username="twitter_name" show_screen_name="false" count="false" float="left"]'); ?></li>
</ul>
</div>
</div>
</div>
<?php } // End woo_bootstrapped_nav()
here in above code add flag images below home url link.

Show WordPress Primary Menu in Zurb Foundation header [_s theme ]

I am creating a theme based on _s & Zurb's Foundation.
I have pretty much got everything set up and ready to start into the CSS, but I am having issues getting the 'primary menu' to show on the top bar.
I want to leave the 'left nav button' where it is, for a highlighted link (possibly contact us or similar), but I want to replace the current content in ul class="right" for the WordPress Primary Menu.
Here is what I have in the current header id="masthead"
<header id="masthead" class="site-header" role="banner">
<div class="row">
<div class="site-branding">
<h1 class="site-title">
<?php bloginfo( 'name' ); ?></h1>
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
</div>
<div class="contain-to-grid sticky">
<nav id="site-navigation" class="top-bar" data-topbar data-options="sticky_on: large" role="navigation">
<ul class="title-area">
<li class="name">
<h4><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
<?php bloginfo( 'name' ); ?></a></h4>
</li>
<li class="toggle-topbar menu-icon">Menu</li>
</ul>
<section class="top-bar-section">
<!-- Right Nav Section -->
<ul class="right">
<li class="active">Right Button Active</li>
<li class="has-dropdown">
Right Button Dropdown
<ul class="dropdown">
<li>First link in dropdown</li>
</ul>
</li>
</ul>
<!-- Left Nav Section -->
<ul class="left">
<li>Left Nav Button</li>
</ul>
</section>
</nav><!-- #site-navigation -->
</div>
</div> <!-- row -->
</header><!-- #masthead -->
You need to use wp_nav_menu().
http://codex.wordpress.org/Function_Reference/wp_nav_menu
You will also need to use a walker which customises the output of wp_nav_menu() to match that of Foundation's top bar.
You can add this to your funtions.php
class guts_top_bar_walker extends Walker_Nav_Menu {
function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
$element->has_children = !empty($children_elements[$element->ID]);
$element->classes[] = ( $element->current || $element->current_item_ancestor ) ? 'active' : '';
$element->classes[] = ( $element->has_children ) ? 'has-dropdown' : '';
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$item_html = '';
parent::start_el( $item_html, $item, $depth, $args, $id );
$output .= ($depth == 0) ? '<li class="divider"></li>' : '';
$classes = empty($item->classes) ? array() : (array) $item->classes;
if ( in_array( 'section', $classes ) ) {
$output .= '<li class="divider"></li>';
$item_html = preg_replace('/<a[^>]*>(.*)<\/a>/iU', '<label>$1</label>', $item_html);
}
$output .= $item_html;
}
function start_lvl( &$output, $depth = 0, $args = array() ) {
$output .= "\n<ul class=\"sub-menu dropdown\">\n";
}
}
You specify the walker within wp_nav_menu(). Replace the section area of the top bar in your header with the following;
<section class="top-bar-section">
<?php wp_nav_menu(array('container' => false, 'menu_class' => 'left', 'theme_location' => 'primary-left', 'fallback_cb' => false, 'walker' => new guts_top_bar_walker() )); ?>
<?php wp_nav_menu(array('container' => false, 'menu_class' => 'right', 'theme_location' => 'primary', 'walker' => new guts_top_bar_walker() )); ?>
</section>
Even if you want a highlighted link to remain in the left section, I'd recommend setting up another menu so that you can make future changes directly through the wordpress dash, instead of requiring edits to your theme.
You can register a new menu area like this in functions.php:
register_nav_menu( 'primary-left', __( 'Left Navigation Menu', 'guts' ) );
more info here: http://codex.wordpress.org/Function_Reference/register_nav_menus

Resources