I have 3 menus created in WordPress and the main menu is retrieved using wp_nav_menu() . I also want to retrieve the other menu please guide me how to do so.
You need to pass it an args array, and declare the theme_location key.
wp_nav_menu( array(
'theme_location' => 'header_main'
) ):
and
wp_nav_menu( array(
'theme_location' => 'header_secondary'
) ):
To retrieve other menu, you need to pass argument menu with menu name like this:
wp_nav_menu( array( 'menu' => 'name of the menu' ) );
You are able to create custom menu in your theme. Add this code to the function.php of your theme.
function lanparts_menu_setup(){
add_theme_support('menus','woocommerce');
register_nav_menu('woocommercemenu','Woocommerce Menu Navigation');
}
add_action('after_setup_theme','lanparts_menu_setup');
for more detail that follow this link
Related
I cannot seem to figure out how to replace my top navigation menu (nav id="top-menu-nav") with the WordPress menu that I have already created called "Shop".
I have tried a number of different times replacing the 'menu' with 'top_menu_nav' or 'top_menu' but it doesn't recognize the location to replace the menu with the "Shop" menu.
if(strpos($_SERVER['REQUEST_URI'], 'product') !== false){
wp_nav_menu( array( 'menu' => 'Shop' ) );
}
The current code places the 'Shop' menu on the left side of the product page with no style and does not replace the menu that is currently in the header.
Actually you need to show shop menu for all woocommerce pages. right?
In the menu calling in header, please add
if (is_woocommerce()) {
wp_nav_menu( array( 'menu' => 'Shop' ) );
} else {
wp_nav_menu( array( 'menu' => 'default menu name' ) );
}
I am trying to get a menu with few links, and show their/link/page featured image. following is my code for functions.php.
function register_my_menus() {
register_nav_menus(
array(
'main-menu' => __( 'Main Menu' ),
'useful-links' => __( 'Userful Links' )
)
);
}
add_action( 'init', 'register_my_menus' );
and this is where i am calling it in the page.
<?php wp_nav_menu( array( 'theme_location' => 'useful-links', 'sort_column' => 'menu_order', 'container_class' => 'useful-links', 'menu'=>'Posts Menu' ) ); ?>
i know something is missing but kindly advice. my page look and feel allow 6 links and their images.
thanks
This should be in your functions.php to register the menu within WordPress.
if (!function_exists('wp_basicTemplateSetup')) {
function wp_basicTemplateSetup() {
// Register the Main Menus into WordPress
register_nav_menus(array(
'primary' => __('Main Menu', 'theme-name'),
));
}
}
add_action('after_setup_theme', 'wp_basicTemplateSetup');
In your theme, where the menu is sitting you need to tell the menu function, which menu to look for. So..:
// Variable that tells WordPress which menu to use, look at "Theme Location"
// Put this variable either at the top of your theme, of right *before* the function wp_nav_menu
$mainmenu = array(
'theme_location' => 'primary',
'container' => false,
'menu_class' => 'some-menu-css-class',
'depth' => 2
);
// The WordPress menu function
<?php wp_nav_menu($mainmenu); ?>
These 3 components are necessary to get your WordPress menu working.
i m having a problem with menus.
I had a template that wasnt originaly for WP.
so i integrated it.
when i started the site there was only one menu which works great.
i added <?php wp_nav_menu('primary'); ?> and its all ok
Now i need to add another one (custom links in the header section)
sooo i used this method
register_nav_menus( array(
'header' => 'Header menu',
'footer' => 'Footer menu'
) );
and recieved new locations for menus.
for the second menu i added
<?php wp_nav_menu( array( 'theme_location' => 'header', 'menu_class' => 'nav-menu', 'fallback_cb' => false ) ); ?>
now the problem:
there is a primary menu (it has few items)
and the custom menu ( its currently empty)
when i add new page to custom menu its being shown in both primary and custom menus.
if i delete all the items from custom menu, primary menu items are back in place...
what is the problem?
Thank you.
If I understand correctly, it looks like you are pointing to the wrong registered menu in the wp_nav_menu(). Specifically in the theme_location.
When you are building the "second menu" which is the "footer", theme_location should be footer since that is the name you gave it in the register_nav_menus().
<?php wp_nav_menu(
array( 'theme_location' => 'footer', // Change 'header' to 'footer'
'menu_class' => 'nav-menu',
'fallback_cb' => false )
);
?>
I've already created a canvas child-theme. I added my custom page woo-hooks.class.php in the canvas-child folder in which i copied all the code from the original and added here:
$this->hooks['header'] = array(
'woo_top' => array(
'content' => '',
'shortcodes' => 0,
'php' =>'
the following code:
if ( is_user_logged_in() ) {
wp_nav_menu( array( "theme_location" => "top-menu-loggedin" ) );
} else {
wp_nav_menu( array( "theme_location" => "top-menu-loggedout" ) );
}
the code is like it doesn't even exists, I know I've probably mistaken what I have to do, but i couldn't find a clear guide anywhere on how to do this, just some code in some forums with no context about how and where to act (the code i added I found it in a forum, but I guess i didn't add it in the right place). The filter and hooks guides of WP don't make clear WHERE and HOW to call the custom filters and hooks and how to actually make them interact with the existing code... I'm going nuts, please help.
Top menu customization can be performed in header section, that is in child theme's 'header.php' file or in other file, specifying 'theme-location' parameter.
You can write below code, in your child theme,
if (is_user_logged_in()){
wp_nav_menu(array(
'menu_class' => 'member-menu',
'menu' => 'Members',
'theme_location' => 'primary');
);
}else{
wp_nav_menu(array(
'menu_class' => 'top-menu',
'menu' => 'Members non Logged in',
'theme_location' => 'primary')
);
}
Here, 'theme-location' parameter is specifies location of Menu and 'menu' specifies name of Menu.
I am trying to add a class to the default ul generated in a custom wordpress menu.
I have created the custom menu in the backend and set it up fine, after referencing the wordpress codex this is the code I am currently using:
<?php
if ( has_nav_menu( 'main-navigation' ) ) { /* if menu location 'main-navigation' exists then use custom menu */
wp_nav_menu(
array(
'theme_location' => 'Main Navigation',
'menu_class' => 'row',
'items_wrap' => '<ul class="nav">%3$s</ul>',
'walker' => '',
)
);
}
?>
This is generating a div with a class of "row" wrapping around my ul but no class is added to the ul itself. I have seen many people with this problem online but no solutions.
Thanks.
You can achieve this with jQuery by targetting the ul element and adding a class like this:
$(".row ul").addClass( "CLASS-HERE" );
Try this extension from GitHub. It allows you to use Bootstrap navigation components in WordPress with easy.
https://github.com/twittem/wp-bootstrap-navwalker
you can use parameter
'menu_class' => 'nav-menu'