Wordpress Nav - Horizontal Nav with dropdown - php

I'm trying to create a horizontal nav with a drop down in wordpress.
This is the code I'm tryin to make using the wordpress nav:
<ul>
<li>Home</li>
<li>News</li>
<li class="dropdown">
Dropdown
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
</ul>
What I have for the PHP is this:
<?php $defaults = array(
'container_class' => 'dropdown',
'container_id' => '',
'container' => '',
'menu_class' => 'dropbtn',
'menu_id' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
); ?>
<?php wp_nav_menu( $defaults ); ?>
What it puts out is this:
<ul class="dropbtn" id="menu-desktop-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-311" id="menu-item-311">Home</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-266" id="menu-item-266">Name
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-276" id="menu-item-276">Name</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-274" id="menu-item-274">Name</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-275" id="menu-item-275">Name</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-271" id="menu-item-271">Name</li>
</ul>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-270" id="menu-item-270">Name
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-277" id="menu-item-277">Name</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-272" id="menu-item-272">Name</li>
</ul>
</li>
</ul>
It's not getting me what I want. I've tried several other things, but I'm really confused on what I need to change to make this work. Can someone help me?

here is simple dropdown menu on hover
.dropbtn > li {
position: relative;
display: block;
height: 40px;
padding: 0 20px;
float: left;
}
.dropbtn .sub-menu {
position: absolute;
top: 100%;
left: 50%;
display: none;
width: 150px;
margin-left: -75px;
padding: 10px;
background-color: #f0f0f0;
}
.dropbtn .sub-menu li {
display: block;
height: 40px;
line-height: 40px;
text-align: center;
border-bottom: 1px dotted #d0d0d0;
}
.dropbtn > li:hover .sub-menu {
display: block;
}
<ul class="dropbtn" id="menu-desktop-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-311" id="menu-item-311">Home</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-266" id="menu-item-266">Name
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-276" id="menu-item-276">Name</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-274" id="menu-item-274">Name</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-275" id="menu-item-275">Name</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-271" id="menu-item-271">Name</li>
</ul>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-270" id="menu-item-270">Name
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-277" id="menu-item-277">Name</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-272" id="menu-item-272">Name</li>
</ul>
</li>
</ul>

Related

Add icons to wordpress menu

I have some problems with Wordpress.. I tried to add icons from Wordpress -> Appearance -> Menu and it works but they are not clickable. I also want to remove the text from the menu icon and add it to "data-tooltip". And the last question is: How to add the menu item icons in a different element (not the "li" element) for example "span"?
My code should be:
<ul class="clear-list">
<li>
<span class="crt-icon crt-icon-home"></span>
</li>
<li>
<span class="crt-icon crt-icon-portfolio"></span>
</li>
<li>
<span class="crt-icon crt-icon-references"></span>
</li>
<li>
<span class="crt-icon crt-icon-contact"></span>
</li>
</ul>
But it actually looks like:
<ul id="menu-main-menu" class="clear-list">
<li id="menu-item-60" class="crt-icon crt-icon-home menu-item menu-item-type-post_type menu-item-object-page menu-item-home current-menu-item page_item page-item-7 current_page_item menu-item-60">Home
</li>
<li id="menu-item-55" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-55">Experience
</li>
<li id="menu-item-54" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-54">Portfolio
</li>
<li id="menu-item-58" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-58">Testimonials
</li>
<li id="menu-item-53" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-53">Contacts
</li>
</ul>
I hope you can help me! :)
Add icons: easiest way is to add icons via CSS.
You can to add class for each link in admin and to add icon as pseudo-element, for example if your icon is image:
.crt-icon a:after {
background: url(https://www.iconfinder.com/data/icons/ionicons/512/icon-ios7-contact-512.png);
background-size: cover;
content: '';
display: block;
height: 15px;
width: 15px;
}
If your icon is font-family - you can add it in 'content' CSS rule.
Add tooltip and remove text: you can do it with jquery:
$( '#menu-main-menu a' ).each( function () {
$( this ).attr( 'data-tooltip', $( this ).text() ).empty();
})

Sub menus have disappeared

My web site has suddenly come down with some problems, with no known changes. Most prominently, no sub menus appear. The html is there, everything appears to be there in wordpress in the admin panel to be set up right. But no sub menus appear on hover. Site is btwimages.com.
<!-- ################ TOP MENU SECTION ################ -->
<!-- **Top-Menu** -->
<div id="top-menu">
<div class="container">
<ul id="menu-main-menu" class="menu"><li id="menu-item-2351" class="home menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home"><span class="hoverL"> <span class="hoverR"> </span> </span>Home</li>
<li id="menu-item-2352" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children"><span class="hoverL"> <span class="hoverR"> </span> </span>About Us
<ul class="sub-menu">
<li id="menu-item-2316" class="menu-item menu-item-type-post_type menu-item-object-page">About BTW images</li>
<li id="menu-item-2318" class="menu-item menu-item-type-post_type menu-item-object-page">Testimonials</li>
<li id="menu-item-2317" class="menu-item menu-item-type-post_type menu-item-object-page">Our Team</li>
</ul>
</li>
<li id="menu-item-2353" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children"><span class="hoverL"> <span class="hoverR"> </span> </span>Services
<ul class="sub-menu">
<li id="menu-item-2354" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children">Real Estate
<ul class="sub-menu">
<li id="menu-item-2341" class="menu-item menu-item-type-post_type menu-item-object-page">Photography</li>
<li id="menu-item-2340" class="menu-item menu-item-type-post_type menu-item-object-page">Floor Plans</li>
<li id="menu-item-2343" class="menu-item menu-item-type-post_type menu-item-object-page">Virtual Tours</li>
<li id="menu-item-2342" class="menu-item menu-item-type-post_type menu-item-object-page">Video Tours</li>
<li id="menu-item-2339" class="menu-item menu-item-type-post_type menu-item-object-page">Brochures</li>
<li id="menu-item-3454" class="menu-item menu-item-type-post_type menu-item-object-page">TrueVision</li>
</ul>
</li>
<li id="menu-item-2888" class="menu-item menu-item-type-post_type menu-item-object-page">3D Immersion</li>
<li id="menu-item-3098" class="menu-item menu-item-type-post_type menu-item-object-page">Virtual Staging</li>
<li id="menu-item-2344" class="menu-item menu-item-type-post_type menu-item-object-page">Video</li>
<li id="menu-item-2336" class="menu-item menu-item-type-post_type menu-item-object-page">General Photography</li>
<li id="menu-item-2337" class="menu-item menu-item-type-post_type menu-item-object-page">Marketing</li>
</ul>
</li>
<li id="menu-item-2329" class="menu-item menu-item-type-post_type menu-item-object-page"><span class="hoverL"> <span class="hoverR"> </span> </span>Portfolio</li>
<li id="menu-item-2355" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children"><span class="hoverL"> <span class="hoverR"> </span> </span>Pricing
<ul class="sub-menu">
<li id="menu-item-2333" class="menu-item menu-item-type-post_type menu-item-object-page">Real Estate Photography</li>
<li id="menu-item-2912" class="menu-item menu-item-type-post_type menu-item-object-page">3D Immersion Tour</li>
<li id="menu-item-2331" class="menu-item menu-item-type-post_type menu-item-object-page">Floor Plans</li>
<li id="menu-item-2332" class="menu-item menu-item-type-post_type menu-item-object-page">Brochures</li>
<li id="menu-item-3099" class="menu-item menu-item-type-post_type menu-item-object-page">Virtual Staging</li>
<li id="menu-item-3455" class="menu-item menu-item-type-post_type menu-item-object-page">TrueVision</li>
</ul>
</li>
<li id="menu-item-2356" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children"><span class="hoverL"> <span class="hoverR"> </span> </span>News
<ul class="sub-menu">
<li id="menu-item-2328" class="menu-item menu-item-type-post_type menu-item-object-page">Latest News</li>
<li id="menu-item-2325" class="menu-item menu-item-type-post_type menu-item-object-page">BTWeen the lines</li>
<li id="menu-item-2327" class="menu-item menu-item-type-post_type menu-item-object-page">Latest Home Tours</li>
</ul>
</li>
<li id="menu-item-2357" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children"><span class="hoverL"> <span class="hoverR"> </span> </span>Support
<ul class="sub-menu">
<li id="menu-item-2482" class="menu-item menu-item-type-post_type menu-item-object-page">FAQ</li>
<li id="menu-item-2910" class="menu-item menu-item-type-post_type menu-item-object-page">3D Immersion FAQs</li>
<li id="menu-item-2347" class="menu-item menu-item-type-post_type menu-item-object-page">Help Videos</li>
<li id="menu-item-2349" class="menu-item menu-item-type-post_type menu-item-object-page">Preparation Checklist</li>
<li id="menu-item-2348" class="menu-item menu-item-type-post_type menu-item-object-page">Media Terms of Use</li>
<li id="menu-item-2350" class="menu-item menu-item-type-post_type menu-item-object-page">Service Policies</li>
</ul>
</li>
<li id="menu-item-2358" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children"><span class="hoverL"> <span class="hoverR"> </span> </span>Contact Us
<ul class="sub-menu">
<li id="menu-item-2320" class="menu-item menu-item-type-post_type menu-item-object-page">Learn More</li>
<li id="menu-item-2321" class="menu-item menu-item-type-post_type menu-item-object-page">Request Service</li>
</ul>
</li>
</ul> </div>
</div><!-- **Top-Menu - End** -->
<!-- ################ TOP MENU SECTION END ################ -->
If you can't fixed it through admin panel, you can add this code to your header or footer:
jQuery('.menu-item-has-children').hover(function() {
jQuery('.menu-item-has-children .sub-menu').css('display', 'none');
jQuery(this).find('.sub-menu').css('display', 'block');
});

Wordpress expand sub-menu when clicking on parent

I am making a wordpress theme using _s as a basis. I am trying to style the menu. So far I don't have any particular CSS on the menu. I have looked at the (responsive) menu for the Twenty Sixteen theme, and I want to have the same the of menu, but only the "responsive" menu for smaller screens. On my site, the menu does not have to be responsive though. The menu (on smaller screens) looks like this, which is what I want:
Twenty Sixteen theme demo: https://twentysixteendemo.wordpress.com/ (You have to resize to a small screen to see the menu I am talking about)
I want that type of menu largely because it has the ability for a "expand/drop-down button" that can show sub-content in the menu.
So my question is: how can I style my menu so that it looks like the Twenty Sixteen theme's (mobile/tablet) menu including the button that expands the menu sub-categories?
I have searched the web for days without finding info on this. It seems every article that merely address the issue are just copy-paste of other badly explained articles.
This is the rendered HTML I have for my menu right now:
<ul id="primary-menu" class="main-menu"><li class="has-children menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1706">Group 1
<ul class="sub-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1707">Sub Group 1
<ul class="sub-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1708">Image</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1709">Image</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1710">Image</li>
</ul>
</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1711">Sub Group 2
<ul class="sub-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1712">Sub Group Level 3
<ul class="sub-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1713">Image</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1714">Image</li>
</ul>
</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1715">Image</li>
</ul>
</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1730">Image</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1731">Image</li>
</ul>
</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1718">Group 2
<ul class="sub-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1719">Image</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1720">Image</li>
</ul>
</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1721">Group 3
<ul class="sub-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1722">Image</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1723">Image</li>
</ul>
</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1724">Group 4
<ul class="sub-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-1725">Sub Group 3
<ul class="sub-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1726">Image</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1727">Image</li>
</ul>
</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1728">Image</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1729">Image</li>
</ul>
</li>
</ul>
This is the menu in my header.php
<div class="menu-container">
<nav id="site-navigation" class="main-navigation" role="navigation">
<?php wp_nav_menu(array(
'theme_location' => 'primary',
'sort_column' => 'menu_order',
'menu' => 'Categories',
'container_class' => 'main-menu',
'menu_id' => 'primary-menu',
'menu_class' => 'main-menu'
) ); ?>
</nav><!-- #site-navigation -->
</div><!-- #menu-container -->
What my menu looks like now:
You can achieve this with javascript (jquery) or only with css.
Css example: https://codyhouse.co/gem/css-multi-level-accordion-menu/
jquery example: https://perishablepress.com/jquery-accordion-menu-tutorial/
hope this helps

WordPress: wp_nav_menu sometimes is messed up

I use the wordpress funcion wp_nav_menu() to display a hierarchical menu I created in my WP menu. Here's the snippet:
<?php wp_nav_menu('show_home=1&menu_class=page-navi&sort_column=menu_order'); ?>
Here's its html output:
<div class="menu-default-container"><ul class="page-navi" id="menu-default"><li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-127" id="menu-item-127">Home Page</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-128" id="menu-item-128">Il film
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-129" id="menu-item-129">Di che cosa parla?</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-133" id="menu-item-133">Una storia di occasioni</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-130" id="menu-item-130">Il Regista</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-131" id="menu-item-131">Il “maestro”</li>
</ul>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-139" id="menu-item-139">Incontri e discussioni</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-153" id="menu-item-153">News ed eventi</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-141" id="menu-item-141">Film e lavoro in classe
<ul class="sub-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-142" id="menu-item-142">Il titolo del film</li>
</ul>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-134" id="menu-item-134">Interviste</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-19 current_page_item menu-item-138" id="menu-item-138">Sponsor e collaborazioni</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-151" id="menu-item-151">Contatti</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-158" id="menu-item-158">Credits</li>
</ul></div>
The problem is that sometimes it's displayed properly:
.. and others isn't:
I checked the source code and it's THE SAME!! :o
Don't know what to think. These things scare me! :P
Here's the website if you want to try to reproduce this (if you're lucky.. in the nights of full moon)..
This is happening because of this style:
ul li {
display: inline;
padding: 2px;
}
Adding the following style to your css should fix your problem:
.menu-default-container ul li {
display: block !important;
}

how do I remove additional anchor tag in a bootstrapped WordPress dropdown menu?

Code used in functions.php to create WordPress [Dropdown enabled] Twitter Bootstrap
Menu: http://pastebin.com/HCxCcBmG
Code used in header.php: http://pastebin.com/7eTHTjij
Here's what gets generated for the dropdown menu code:
<ul class="dropdown-menu">
<li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-29">
site design
</li>
<li id="menu-item-30" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-30">
app design
</li>
<li id="menu-item-31" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-31">
windows
</li>
<li id="menu-item-32" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-32">
mac
</li>
</ul>
How do I remove the additional anchor tag/link genereated in the first dropdown menu link? Like this:
<ul class="dropdown-menu">
<li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-29">
site design
</li>
<li id="menu-item-30" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-30">
app design
</li>
<li id="menu-item-31" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-31">
windows
</li>
<li id="menu-item-32" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-32">
mac
</li>
</ul>

Categories