lobidouble.blogg.se

Wordpress display menu
Wordpress display menu











wordpress display menu

The above conditional statement will return true if the page in question isn't the home page or the front page. You could also combine them: 'secondary', Wrap those menu functions in a conditional statement that's applicable to your case. If you have set your home page to display your latest posts then you should use is_home(), if you've set your home page as the front page through Reading > Settings > Front page displays, then you should use is_front_page(). Use the built in conditionals Wordpress provides: If you want your primary menu not to appear on home page do like Now for displaying primary menu only in home page wrap is_home() like

Wordpress display menu code#

'secondary_navigation_menu' => 'My Custom Footer Menu',Īnd after if ( has_nav_menu( 'primary' ) : ?> section there should be code to display menu something like wp_nav_menu( array(Īfter this add 'secondary_navigation_menu' ) ) 'secondary_menu' => 'Secondary Navigation Menu', Now in your functions.php register another menu location register_nav_menus( array( If you go through your header.php there should be something like this. 'menu_class' => 'nav navbar-nav navbar-right' 'container_class' => 'navbar navbar-default', 'secondary' => _( 'Secondary Menu', 'themename' ),

wordpress display menu

'primary' => esc_html_( 'Primary', 'themename' ), How can i fix it?įunction.php file register_nav_menus( array( What I'm try to do is show my primary menu bar only in my main home page, and show secondary menu on my about us page, services page, etc. The problem is both menu bar appeared at the same time so i have double menu bar on the top of my home page and also my about us page. (but using the same css method mentioned above too) ul.I have added my secondary menu on my function.php file and WordPress also allowed me to choose the secondary menu. then you simply just set your css like this, no jQuery needed. I pretty much just realised, if your sub menus only appear on the current-menu-item page itself, and you don't wan't the sub menu to appear whilst on another page from the main menu. Let me know if you can't figure out the CSS. Then after this, you have to be clever with your css and position your ul.sub-menu absolute to the parent ul.menu - and make sure the li.menu-item and ul.menu overflow is set to visible, but li.menu-item has to have NO positioning. this basically, when a menu link is clicked, hides all sub menu's using our variable, then finds any child ul's (sub menu) and set's to 'display block' if these li's have current class's, they're set to 'display: block', this is for page reloads so the current menu is visible on page load.

wordpress display menu

$('li.current-menu-parent, li.current-menu-item').find('ul').show() this variable makes all sub menu ul's 'display: none ' So using some jquery like below, you can control visibility of those sub elements. You can see in the markup that wordpress generates a class for each element.Īnd when your menu item is active, wordpress add's active class current-menu-item or current-menu-parent to the li's See your generated markup in the dom, it will look like this sort of. You will notice this menu PHP generates a unordered list with your sub menu as a nested unordered list. If your developing this theme with your own html mark up and css then should be fairly easy.













Wordpress display menu