wordpress wp menu in home page and inner page - php

My main wp_nav_menu is called header-menu
and that menu like this
Home
About
Insight
Test 1
Test 1
About 2
Test
Test
I want to call this menu in home page without showing sub items . That can i do using
<?php
wp_nav_menu( array(
'menu_class' => 'main-nav navbar-nav ml-auto',
'container' => false,
'theme_location' => 'header-menu',
'depth' => 1,
) );
?>
But after when i go to the Insight page i want to show secondary main menu and secondary menu (only test1 and test2) How can i do this

Create a new menu and conditionally call in home page , that would be easy solution

Related

How to make a Menu be added to a menu location by default in Wordpress

I am trying to add a menu for my new WordPress theme, what I want to happen is, the menu to be added to the registered menu location by default instead of having to go to the dashboard and selecting the menu that I want to make appear there.
I have looked at several tutorials and they all add the menu manually
This is the functions.php file which has the location registered.
register_nav_menus( array(
'main-menu' => esc_html__( 'Primary Menu', 'tester' ),
'footer-social-menu' => esc_html__( 'Social Menu', 'tester' )
));
And I call this using
<?php wp_nav_menu(array('theme_location' => 'footer-social-menu')); ?>
But WordPress still didn't show the menu by default in
Customizing ▸ Menus View ▸ All Locations
The Social Menu Area still says
---Select---
Can this be done?
(Note: The Menu is there, I just have to select it manually, i.e the menu area and the menu are successfully registered and working)
I got this to work
<?php
wp_nav_menu(array(
'theme_location' => 'footer-social-menu',
'menu' => 'Social Menu',
'fallback_cb' => false
));
?>
By Adding
'menu' => 'Social Menu',
as shown when calling the created Menu

Parent link in mobile nav not clickable in JointsWP

I'm currently using JointsWP for a WordPress theme. I'm running into an issue where the parent links in my dropdown menu are not clickable.
I searched the Foundation forums and found this thread that I thought would be helpful. It mentions adding data-options="mobile_show_parent_link: true" to the nav class top-bar.
JointsWP doesn't use the nav tag for it's menu, but I did add it where I thought it should be, which is the ul wrapper in the /assets/functions/menu.php file like so:
// The Top Menu
function joints_top_nav() {
wp_nav_menu(array(
'container' => false, // Remove nav container
'menu_class' => 'vertical medium-horizontal menu', // Adding custom nav class
'items_wrap' => '<ul id="%1$s" class="%2$s" data-options="mobile_show_parent_link: true" data-responsive-menu="accordion medium-dropdown">%3$s</ul>',
'theme_location' => 'main-nav', // Where it's located in the theme
'depth' => 5, // Limit the depth of the nav
'fallback_cb' => false, // Fallback function (see below)
'walker' => new Topbar_Menu_Walker()
));
} /* End Top Menu */
However, this is not working.
I've also tried:
data-options="is_hover: false"
Does anyone have any ideas on how to make the top parent link clickable when the submenu is expanded in mobile for JointsWP?
Thanks!

Wordpress menus

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 )
);
?>

Styling of Navigation Menu WP for Guest vs. Logged In User

I have a problem with a Wordpress website I'm creating for a church. They'd like a seperate part only their members can see. I installed the plug-in WP-Members and created two menus, one for guests (not-logged-in-users) and for users (logged-in-users). I put in some code into the header.php, telling it to show logged-in-users one menu and not-logged-in-users the other. So far so good.
Problem is that the styling changes when a user logs in. A not-logged-in-user sees the navigation menu the way it is supposed to be. When a user logs in, the sub-indicators disappear, auto width doesn't work and the slider, just beneath the navigation menu also magically stops working. This makes me believe it might be a conflict with two plug-ins, or something like that
Code i used to show guest one menu and users the other:
<div id="navigation" class="clearfix">
<?php
if ( is_user_logged_in() ) {
wp_nav_menu( array(
'theme_location' => 'main nav',
'menu' => 'logged-in-menu',
'sort_column' => 'menu_order',
'menu_class' => 'sf-menu sf-js-enabled sf-shadow',
'fallback_cb' => 'default_menu'
));
} else {
wp_nav_menu( array(
'theme_location' => 'main nav',
'menu' => 'logged-out-menu',
'sort_column' => 'menu_order',
'menu_class' => 'sf-menu sf-js-enabled sf-shadow',
'fallback_cb' => 'default_menu'
));
}
?>
</div>
The website is www.vineyardkollumerzwaag.nl/nieuw/
Username: Test
Password: test
When logged in I'm seeing a JavaScript error coming from the script /wp-content/mu-plugins/notes/admin-bar-rest.js - the error is that an Object does not have the method 'on'
Looking a bit closer, you are including jQuery version 1.6.2, .on() was added to jQuery in version 1.7 - try updating the version of jQuery included in your site to 1.7+ and that should fix the issue

Wordpress: add custom ID to ul in wp_nav_menu

I am trying to alter the wp_nav_menu to output the html like the below example.
<div class="menu">
<ul id="menu">
The original output
<div class="menu">
<ul>
I cant do it with jQuery or javascript, Its have to be php code
wp_nav_menu accepts the key menu_id in its options array. Set it to the ID you want, e.g:
wp_nav_menu(array(
'menu_id' => 'menu'
));
You can explicitly set the id in the html by defining items_wrap, and make sure walker is not set to some custom function:
wp_nav_menu( array(
'theme_location' => 'main-menu'
'items_wrap' => '<ul id="menu" class="%2$s">%3$s</ul>',
'walker' => '',
));
This is incomplete info; 1st attempt to use:
'fallback_cb' => false,
If you menu doesn't appear, that means you have not created any menu and that means its taking the fallback function take care for that.
So go and create a menu first. :D
Giving the ul an id that's the same as the class of its container is asking for trouble, but this should work:
<?php
function showMenu(){
$args = array(
'menu_id' => 'menu'
);
wp_nav_menu($args);
}
showMenu();
?>
The WordPress Codex has a page detailing all options for the wp_nav_menu() function: http://codex.wordpress.org/Function_Reference/wp_nav_menu

Categories