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 / Customizing the User Menu in WPResidence Headers

Customizing the User Menu in WPResidence Headers

360 views 0

The user menu in WPResidence headers is a crucial element for user interaction, providing quick access to account-related functions. This guide will walk you through various ways to customize the user menu to enhance user experience and match your website’s design.

Understanding the Default User Menu

By default, WPResidence displays a user menu in the header that typically includes options for login, register, and access to the user dashboard. The appearance and functionality of this menu can be customized to better suit your needs.

Modifying User Menu Content

To add or remove items from the user menu, you can use the ‘wpresidence_user_menu_items’ filter. Add this to your child theme’s functions.php:


function custom_user_menu_items($menu_items) {
// Add a new menu item
$menu_items['custom_page'] = array(
'label' => __('Custom Page', 'wpresidence-child'),
'url' => home_url('/custom-page/'),
);
// Remove an existing item
unset($menu_items['my_profile']);

return $menu_items;
add_filter(‘wpresidence_user_menu_items’, ‘custom_user_menu_items’);

Styling the User Menu

To customize the appearance of the user menu, add these styles to your child theme’s style.css:


.user_menu {
background-color: #f8f8f8;
border-radius: 5px;
}
.user_menu_register {
color: #0073e1;
font-weight: bold;
}
.user_menu_register:hover {
text-decoration: underline;
}
.user_menu_logged .menu_user_picture {
border: 2px solid #0073e1;
}

Customizing User Menu for Logged-in Users

You can add custom functionality for logged-in users. Here’s an example that adds a greeting and a custom link:


function custom_logged_in_menu($items) {
if (is_user_logged_in()) {
$user = wp_get_current_user();
$items = '<li>Welcome, ' . $user->display_name . '!</li>' . $items;
$items .= '<li><a href="' . home_url('/my-favorites/') . '">My Favorites</a></li>';
}
return $items;
}
add_filter('wpresidence_user_menu_items', 'custom_logged_in_menu');

Adding Icons to User Menu Items

Enhance the visual appeal of your user menu by adding icons. You can use Font Awesome icons, which are included with WPResidence:


function add_icons_to_user_menu($items) {
foreach ($items as $key => &$item) {
switch ($key) {
case 'add_listing':
$item['icon'] = 'fas fa-plus';
break;
case 'my_properties':
$item['icon'] = 'fas fa-home';
break;
// Add more cases as needed
}
}
return $items;
}
add_filter('wpresidence_user_menu_items', 'add_icons_to_user_menu');

Then, in your child theme’s style.css:


.user_menu_item .menu_icon {
margin-right: 5px;
}

Creating a Custom User Menu Template

For more extensive customizations, you can create a custom template for the user menu. Create a file named ‘user-menu-custom.php’ in your child theme and add:


<?php
$current_user = wp_get_current_user();
$user_custom_picture = get_the_author_meta('custom_picture', $current_user->ID);
$user_small_picture = get_the_author_meta('small_custom_picture', $current_user->ID);
if (is_user_logged_in()) {
?>
<div class="user_menu user_loged">
<div class="menu_user_picture" style="background-image: url('<?php echo esc_url($user_custom_picture); ?>');"></div>
<ul class="user_menu_list">
<li><a href="<?php echo esc_url(home_url('/my-profile/')); ?>"><i class="fas fa-user"></i> My Profile</a></li>
<li><a href="<?php echo esc_url(home_url('/my-properties/')); ?>"><i class="fas fa-home"></i> My Properties</a></li>
<li><a href="<?php echo wp_logout_url(home_url()); ?>"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
</ul>
</div>
<?php
} else {
?>
<div class="user_menu">
<a href="<?php echo esc_url(home_url('/login/')); ?>" class="user_menu_login">Login</a>
<a href="<?php echo esc_url(home_url('/register/')); ?>" class="user_menu_register">Register</a>
</div>
<?php
}
?>

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


function custom_user_menu_template($template) {
return get_stylesheet_directory() . '/user-menu-custom.php';
}
add_filter('wpresidence_user_menu_template', 'custom_user_menu_template');

Adding AJAX Functionality to the User Menu

To enhance user experience, you can add AJAX functionality to the user menu. Here’s an example that loads the user’s favorite properties without a page reload:


// In your child theme's functions.php
function load_favorites_ajax() {
check_ajax_referer('my_favorites_nonce', 'security');
$user_id = get_current_user_id();
$favorites = get_user_meta($user_id, 'favorite_properties', true);
if (!empty($favorites)) {
foreach ($favorites as $property_id) {
echo '<li>' . get_the_title($property_id) . '</li>';
}
} else {
echo '<li>No favorites found</li>';
}
wp_die();
add_action('wp_ajax_load_favorites', 'load_favorites_ajax');

Add this JavaScript to your child theme:


jQuery(document).ready(function($) {
$('.load-favorites').on('click', function(e) {
e.preventDefault();
$.ajax({
url: wpresidence_ajax_vars.ajaxurl,
type: 'POST',
data: {
action: 'load_favorites',
security: wpresidence_ajax_vars.nonce
},
success: function(response) {
$('.favorites-list').html(response);
}
});
});
});

Responsive Design for User Menu

Ensure your user menu looks good on all devices by adding these responsive styles to your child theme’s style.css:


@media only screen and (max-width: 768px) {
.user_menu {
position: absolute;
right: 15px;
top: 15px;
}
.user_menu_list {
position: absolute;
top: 100%;
right: 0;
background: #fff;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
display: none;
}
.user_menu:hover .user_menu_list {
display: block;
}
}

By implementing these customizations, you can create a user menu that not only matches your website’s design but also provides a more intuitive and efficient user experience. Remember to test all changes thoroughly, especially when adding new functionality or modifying existing features.

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