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' )); ?>
Related
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>
I don't understand why it's impossible for me to get my custom menu on my front-end page
I use:
<?php
wp_nav_menu( array(
'theme_location' => 'jdsMainMenu',
'depth' => '1',
'menu_class' => 'jds-main-menu-list',
'menu_id' => 'jds-nav',
'container' => '',
'items_wrap' => '<ul class="jds-main-menu-list">%3$s</ul>'
));
?>
I have my menu in WordPress back office.
I try to make:
var_dump(get_registered_nav_menus());
My menu is available: but nothing display with wp_nav_menu...
Maybe some one have an idea...
I am sure you are using correct ID for theme location
screenshot
function register_my_menus() { register_nav_menus(
array(
'jdsMainMenu' => __( 'Navigation Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
wp_nav_menu( array(
'theme_location' => 'jdsMainMenu',
'depth' => '1',
'menu_class' => 'jds-main-menu-list',
'menu_id' => 'jds-nav',
'container' => '',
'items_wrap' => '<ul class="jds-main-menu-list">%3$s</ul>'
));
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>
Working on Wordpress menu: with Bootstrap
My ul li gets wrap within Ul and creates Div.
Screenshot attached:
It seems it automatically adds classes to menu li and and prevents the bootstrap styles and classes
My wp menu function :
/**
* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
*/
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
'extra-menu' => __( 'Extra Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
Try changing in the theme template the nav menu function like this :
<?php
$defaults = array(
'theme_location' => '',
'menu' => '',
'container' => '', // <- This empty = no container
'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 );
?>
Source : https://codex.wordpress.org/Function_Reference/wp_nav_menu
Take a look at the container index of the defaults array.
<?php
if ( function_exists('has_nav_menu') && has_nav_menu('primary-menu') ) {
wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'main-nav', 'menu_class' => 'nav fl', 'theme_location' => 'primary-menu' ) );
} else {
?>
I'm trying to add a secondary menu from Wordpress menu management in my functions.php of my child theme for Woothemes Canvas.
I figure there's a way to add it to the array above but I can't get it to work. Thoughts?
Jason, you first need to register your 'new' (secondary) menu with register_nav_menu() like:
add_action( 'init', 'register_my_menu' );
function register_my_menu() {
register_nav_menu( 'secondary-menu', __( 'Secondary Menu' ) );
}
You do this in your theme's functions.php file.
Then you're able to call that menu in your template files. To use your code above, you'll probably want something like:
if ( function_exists('has_nav_menu') && has_nav_menu('secondary-menu') ) {
wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'secondary-nav', 'menu_class' => 'nav fl', 'theme_location' => 'secondary-menu' ) );
}
or maybe
if ( function_exists('has_nav_menu') && has_nav_menu('primary-menu') && has_nav_menu('secondary-menu') ) {
wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'main-nav', 'menu_class' => 'nav fl', 'theme_location' => 'primary-menu' ) );
wp_nav_menu( array( 'sort_column' => 'menu_order', 'container' => 'ul', 'menu_id' => 'secondary-nav', 'menu_class' => 'nav fl', 'theme_location' => 'secondary-menu' ) );
}
The second one will output both menus if they both exist, the first one will probably be used in addition to the one you posted in your initial question.
But in my case, I did not use the init action, just put the menu register function in my child theme's function.php file
register_nav_menu( 'footer', 'Footer Menu' );