WP Residence Help WP Residence Help

  • WpEstate
  • How to Build Your Website
  • Video Tutorials
  • Client Support
  • API
Home / Technical how to | Custom Code Required, WpResidence 5.0 / Implementing and Customizing Mega Menus in WPResidence

Implementing and Customizing Mega Menus in WPResidence

401 views 0

Implementing and Customizing Mega Menus in WPResidence

Mega menus offer an effective way to organize and display large amounts of navigation options in a visually appealing manner. WPResidence provides built-in support for mega menus, allowing you to create complex navigation structures for your real estate website. This guide will walk you through the process of implementing and customizing mega menus in WPResidence.

Enabling Mega Menus in WPResidence

First, ensure that mega menus are enabled in your theme settings:

  1. Navigate to WPResidence Theme Options
  2. Look for the “Header” or “Navigation” section
  3. Find the option to enable mega menus (it might be labeled “Enable Mega Menus” or similar)
  4. Set this option to “Yes” or “Enabled”
  5. Save your changes

Creating a Basic Mega Menu

To create a mega menu:

  1. Go to Appearance > Menus in your WordPress dashboard
  2. Select your primary navigation menu or create a new one
  3. Add a top-level menu item that will become your mega menu
  4. Add sub-menu items under this top-level item
  5. To create columns, add second-level items under your sub-menu items
  6. Save your menu

Styling Your Mega Menu

WPResidence provides some default styling for mega menus, but you can customize it further. Add the following CSS to your child theme’s style.css file:


.wpresidence-navigation-menu .menu-item-has-megamenu {
position: static;
}
.wpresidence-navigation-menu .megamenu {
position: absolute;
left: 0;
right: 0;
padding: 15px;
background-color: #ffffff;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.wpresidence-navigation-menu .megamenu-column {
float: left;
width: 25%; /* Adjust based on your desired column count */
padding: 0 15px;
}
.wpresidence-navigation-menu .megamenu-title {
font-weight: bold;
margin-bottom: 10px;
color: #333333;
}
.wpresidence-navigation-menu .megamenu-column ul {
list-style: none;
padding: 0;
margin: 0;
}
.wpresidence-navigation-menu .megamenu-column li {
padding: 5px 0;
}
.wpresidence-navigation-menu .megamenu-column a {
color: #666666;
text-decoration: none;
}
.wpresidence-navigation-menu .megamenu-column a:hover {
color: #0073e1;
}

Adding Icons to Mega Menu Items

Enhance your mega menu with icons:

  1. Edit a menu item in Appearance > Menus
  2. In the “CSS Classes” field, add a class for your desired icon (e.g., “fas fa-home” for a home icon using Font Awesome)

Then, add this CSS to style the icons:


.wpresidence-navigation-menu .megamenu-column li i {
margin-right: 5px;
width: 20px;
text-align: center;
}

Creating a Full-Width Image in Mega Menu

To add a full-width image to your mega menu, you’ll need to customize the menu walker. Create a file named custom-mega-menu-walker.php in your child theme and add the following code:


<?php
class WPResidence_Mega_Menu_Walker extends Walker_Nav_Menu {
function start_lvl(&$output, $depth = 0, $args = array()) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"sub-menu\">\n";
if ($depth === 0) {
$output .= "<li class=\"megamenu-full-width-image\"><img src=\"/path/to/your/image.jpg\" alt=\"Full Width Image\"></li>";
}
}
}

Then, in your child theme’s functions.php file, add:


require_once get_stylesheet_directory() . '/custom-mega-menu-walker.php';
function custom_mega_menu_walker($args) {
return array_merge($args, array(
'walker' => new WPResidence_Mega_Menu_Walker()
));
}
add_filter('wp_nav_menu_args', 'custom_mega_menu_walker');

Style the full-width image with CSS:


.megamenu-full-width-image {
width: 100%;
padding: 0;
margin-bottom: 15px;
}
.megamenu-full-width-image img {
width: 100%;
height: auto;
display: block;
}

Adding a Search Bar to Mega Menu

To include a search bar in your mega menu, add this to your custom menu walker:


function end_lvl(&$output, $depth = 0, $args = array()) {
if ($depth === 0) {
$output .= "<li class=\"megamenu-search\">
<form role=\"search\" method=\"get\" id=\"searchform\" action=\"" . home_url('/') . "\">
<input type=\"text\" value=\"" . get_search_query() . "\" name=\"s\" id=\"s\" placeholder=\"Search properties...\"/>
<button type=\"submit\" id=\"searchsubmit\">Search</button>
</form>
</li>";
}
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul>\n";
}

Style the search bar:


.megamenu-search {
width: 100%;
padding: 15px;
}
.megamenu-search form {
display: flex;
}
.megamenu-search input[type="text"] {
flex-grow: 1;
padding: 8px;
border: 1px solid #ddd;
}
.megamenu-search button {
padding: 8px 15px;
background-color: #0073e1;
color: #ffffff;
border: none;
cursor: pointer;
}

Creating Dynamic Content in Mega Menus

You can populate your mega menu with dynamic content, such as recent listings. Add this to your custom menu walker:


function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
if ($item->object == 'custom' && $item->classes[0] == 'dynamic-listings') {
$output .= "<li class=\"megamenu-column dynamic-listings\"><h4>Recent Listings</h4>";
$recent_listings = new WP_Query(array(
'post_type' => 'estate_property',
'posts_per_page' => 3
));
if ($recent_listings->have_posts()) {
while ($recent_listings->have_posts()) {
$recent_listings->the_post();
$output .= "<div class=\"megamenu-listing\">";
$output .= "<a href=\"" . get_permalink() . "\">" . get_the_title() . "</a>";
$output .= "<span class=\"megamenu-listing-price\">" . get_post_meta(get_the_ID(), 'property_price', true) . "</span>";
$output .= "</div>";
}
}
wp_reset_postdata();
$output .= "</li>";
} else {
parent::start_el($output, $item, $depth, $args, $id);
}
}

Style the dynamic listings:


.megamenu-column.dynamic-listings {
width: 33.33%;
}
.megamenu-listing {
margin-bottom: 10px;
}
.megamenu-listing a {
display: block;
font-weight: bold;
}
.megamenu-listing-price {
color: #0073e1;
}

Making Mega Menus Responsive

Ensure your mega menus look good on all devices:


@media (max-width: 768px) {
.wpresidence-navigation-menu .megamenu {
position: static;
width: 100%;
padding: 0;
}
.wpresidence-navigation-menu .megamenu-column {
width: 100%;
float: none;
}
.megamenu-full-width-image,
.megamenu-search {
display: none;
}
}

Troubleshooting Mega Menu Issues

If you encounter problems with your mega menus, try these solutions:

  • Mega menu not appearing: Ensure it’s enabled in Theme Options and that you have enough sub-menu items
  • Styling issues: Check for conflicting CSS and use your browser’s inspector tool to debug
  • Custom content not showing: Verify that your custom walker is properly hooked and functioning
  • Performance concerns: Optimize images and limit the amount of dynamic content to improve load times

Conclusion

Mega menus in WPResidence offer a powerful way to enhance your site’s navigation and showcase important content. By leveraging the theme’s built-in features and implementing custom solutions, you can create mega menus that are both functional and visually appealing. Remember to test your mega menus across different devices and browsers to ensure a consistent user experience for all visitors to your real estate website.

Technical how to | Custom Code RequiredWpResidence 5.0

Related Articles

  • Technical – How to Change the Minimum Image Dimensions for Property Uploads in WPResidence
  • Introduction to WPResidence Header Customization
  • Understanding WPResidence Header Types: An Overview
  • Customizing the WPResidence Logo Display

WP Residence Documentation

  • 1. General
    • How to Get Support
    • Get your buyer license code.
    • Use SSL / https
    • Server / Theme Requirements
  • 2. Installation
  • 3. Installation FAQ
  • 4. Advanced Search
    • Advanced Search Display Settings
    • Advanced Search Form
    • Geolocation Search for Half Map
    • Save Search Theme Options
    • Advanced Search Colors
  • 5. Agent, Agency & Developers
  • 6. Property Page
  • 7. Properties List
  • 8. Property Taxonomies
  • WpResidence Elementor Studio
  • 10. Blog Posts & Blog List
  • 11. Shortcodes
    • Contact Form
    • Featured Agency/Developer
    • Membership Packages
    • Testimonials
    • Google Map with Property Marker
    • Listings per Agent, Agency or Developer
    • Display Categories
    • Agent List
    • Recent Items Slider
    • Recent items
    • List Properties or Articles by ID
    • Featured Agent
    • Featured Article
    • Featured Property
    • Login & Register Form
    • Icon Content Box Shortcode
  • 12. Widgets
  • Theme Options
    • General Settings
    • User Types Settings
    • Appearance
    • Logos & Favicon
    • Header
    • Footer Style and Colors
    • Price & Currency
    • Property Custom Fields
    • Features & Amenities
    • Listing Labels
    • Theme Slider
    • Permalinks
    • Splash Page
    • Social & Contact
    • Map Settings
    • Pin Management
    • How read from file works
    • General Design Settings
    • Custom Colors Settings
    • Header Design & Colors
    • Mobile Menu Colors
    • User Dashboard Colors
    • Print PDF Design
    • Property, Agent, Blog Lists Design Settings
    • Sidebar Widget Design
    • Font management
    • How to add custom CSS
    • Custom Property Card Unit – Beta version
    • Email Management
    • Import & Export theme options
    • reCaptcha settings
    • YELP API Integration
    • iHomefinder Optima Express IDX
    • MEMBERSHIP & PAYMENT Settings
    • Property Submission Page
    • PayPal Setup
    • Stripe Setup
    • Wire Transfer Payment Method
  • Translation
  • FAQ
  • Pages
  • Header
  • Footer
  • Google or Open Street Maps
  • Payment Options
  • Plugins
    • Included Plugins
    • Third Party Plugins – IDX Compatibility
    • Third Party Plugins – Multi Languages
    • Third party Plugins – Other
  • Technical
    • Technical how to | Custom Code Required
    • Technical: Child Theme

Join Us On

Powered by WP Estate - All Rights Reserved
  • WpEstate
  • How to Build Your Website
  • Video Tutorials
  • Client Support
  • API