clean up wordpress custom navigation - wordpress

i have made a custom menu named "header-menu" and i call it in my header.php:
<?php wp_nav_menu( array(
'container' => '',
'theme_location' => 'header-menu'
) ); ?>
with
'container' => '',
i want to remove the menu wrapper, but the output still has this:
<div class="menu">
<ul>
<li> ... </li>
<li> ... </li>
</ul>
</div>
but i want to get rid of the annoying
<div class="menu">
. how to do that?

It's not clear what you're actually doing here but if you want the container to go away you use:
<?php wp_nav_menu( array(
'container' => false,
) ); ?>
Review this page for more detail.

got it working now:
<?php $defaults = array(
'theme_location' => '',
'menu' => 'footer-menu',
'container' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'items_wrap' => '<ul class="dl-menu">%3$s</ul>',
'depth' => 2
);
wp_nav_menu( $defaults );
?>

Related

WordPress navigation menu is not loading

I am working on my custom theme in wordpress, I have a problem in the navigation in my site, when I open the site, the main navigation is not loading.
Below are the codes.
Any assistance is highly appreciated.
Thanks.
Function.php file
function register_my_menus() {
register_nav_menus( array(
'menu-1' => esc_html__( 'Primary', 'nethub' ),
) );
}
add_action( 'init', 'register_my_menus' );
Then in header.php the code is
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-1',
'menu' => 'primary-menu',
'container' => false,
'items_wrap' => '<ul class="rd-navbar-nav">%3$s</ul>',
)
);
?>
</div>
Have you created a menu in the menus edit screen and set it to the "Primary" location? Also think you can remove the 'menu' => 'primary-menu', from your header.php:
// header.php
<?php
wp_nav_menu(array(
'theme_location' => 'menu-1',
'container' => false,
'items_wrap' => '<ul class="rd-navbar-nav">%3$s</ul>',
));
?>
</div>

how to add custom wordpress Menu using just A tag output

I want to create menu like below code but wordpress generate other code.
help me to generate code like below HTML code
Thanks in advance.
help me to generate below code using wordpress
You can do this by using menu walker class like this:
wp_nav_menu( array(
'container' => false,
'menu' => 'main-menu',
'menu_class' => 'nav navbar_menu',
'walker' => new Custom_Walker_Nav_Menu
)
);
add_theme_support('menu');
function register_newtheme_menu(){
register_nav_menus(
array(
'main-menu'=>_('Main Menu')
)
);
}
add_action('init','register_newtheme_menu');
function add_menuclass($ulclass) {
return preg_replace('/<a /', '<a class="navigation-link w-nav-link" ', $ulclass);
}
add_filter('wp_nav_menu','add_menuclass');
?>
<nav class="menu-hamburger w-nav-menu" role="navigation">
<?php
$defaults = array(
'container' => 'false',
'echo' => false,
'fallback_cb' => false,
//'items_wrap' => '<a id="%1$s" class="%2$s">%3$s</a>',
'depth' => 0
);
//echo wp_nav_menu( $defaults );
echo strip_tags(wp_nav_menu( $defaults ),'<a>');
?>
</nav>

Wordpress Primary menu not updating after reordering menu items

In functions.php, I registered primary menu like this-
<?php
register_nav_menus( array(
'menu-1' => esc_html__( 'Primary', 'intralink' ),
) );
?>
And in Homepage I have used below code:
<?php
wp_nav_menu( array(
'theme_location' => 'Primary',
'container' => 'ul',
'container_class' => 'navbar-collapse collapse',
'menu_class' => 'nav navbar-nav navbar-right'
));
?>
Then after creating a menu from wordpress Menus, nothing happens? Maybe it's not drag drop problem, maybe it's something I did wrong.
Thanks
Theme location should be 'menu-1'
It should look like the following
wp_nav_menu( array(
'theme_location' => 'menu-1',
'container' => 'ul',
'container_class' => 'navbar-collapse collapse',
'menu_class' => 'nav navbar-nav navbar-right'
));
Hope this will solve your issue.

Why do i have duplicated menu on wordpress?

Here i am creating 2 menu sites "Main" and "Central"
if ( function_exists( 'register_nav_menus' ) ) {
register_nav_menus(
array(
'main' => 'Main',
'central' => 'Central'
)
);
}
when i am creating menus on wordpress aperience, menus
and i am puting them on their sites
PRS menu on Main
and central on Central
When i have incerted my menus on web
<?php wp_nav_menu( array('menu' => 'Main','menu_class' => 'menu' )); ?>
<?php wp_nav_menu( array('menu' => 'Central','menu_class' => 'menu' )); ?>
But on my web i am seyng "central" menu 2 times and PRS dont apear.
What is the problem and what solution cn i find?
Try single Register this way & then move on to array - add code below to functions.php:
WP Codex register_nav_menu
<?php
add_action( 'after_setup_theme', 'register_my_menu' );
function register_my_menu() {
register_nav_menu( 'primary', 'Primary Menu' );
}
?>
Display menu on page - add to header.php:
WP Codex wp_nav_menu
<?php
$defaults = array(
'theme_location' => 'primary',
'menu' => 'Primary 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 );
?>
Tip - both of your entries have a 'menu' class:
Your code:
<?php wp_nav_menu( array('menu' => 'Main','menu_class' => 'menu' )); ?>
Change to:
<?php wp_nav_menu( array('menu' => 'Main' )); ?>

Active menu class not working in wordpress

I am developing my own theme (using the functions of Twenty Fourteen (nothing has changed in functions.php)). My header does not contain wp_head() but I am using body_class() in my body tag. My menu is defined as so:
<?php
$menuParameters = array(
'container' => false,
'echo' => false,
'items_wrap' => '%3$s',
'depth' => 0,
);
echo strip_tags(wp_nav_menu( $menuParameters ), '<a>' );
?>
Unfortunately, my current-menu-item is not being applied to my navigation anchors when on a wordpress-created page. Am I missing a function somewhere that renders this class? Thanks in advance?
<?php wp_nav_menu(array(
'container'=> '',
'menu_class' => '',
'menu_id' => '',
)); ?>

Resources