WP Residence Help WP Residence Help

  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / Technical how to | Custom Code Required, WPResidence 5.0 Documentation / Implementing Responsive Design for WPResidence Headers

Implementing Responsive Design for WPResidence Headers

663 views 0

Implementing Responsive Design for WPResidence Headers

Creating a responsive header is crucial for ensuring your real estate website looks great and functions well on all devices. WPResidence provides a solid foundation for responsive design, but you can further customize and enhance the responsiveness of your headers. This guide will walk you through the process of implementing a fully responsive header design in WPResidence.

Understanding WPResidence’s Built-in Responsiveness

WPResidence comes with a responsive framework out of the box. The theme uses media queries to adjust the layout and styling of elements, including headers, based on screen size. However, you may want to fine-tune this responsiveness to better suit your specific design needs.

Customizing Breakpoints

WPResidence uses standard breakpoints, but you can customize these in your child theme. Add the following to your child theme’s functions.php:


function custom_responsive_breakpoints($breakpoints) {
$breakpoints['phone'] = 480;
$breakpoints['tablet'] = 768;
$breakpoints['desktop'] = 1024;
return $breakpoints;
}
add_filter('wpresidence_responsive_breakpoints', 'custom_responsive_breakpoints');

Adjusting Header Layout for Mobile

To create a more compact header for mobile devices, add this to your child theme’s style.css:


@media only screen and (max-width: 768px) {
.header_wrapper {
padding: 10px 0;
}
.logo {
max-width: 150px;
}
.navbar-nav > li > a {
padding: 5px 10px;
}
}

Implementing a Mobile Menu

WPResidence includes a mobile menu by default, but you can customize its appearance and behavior. First, ensure the mobile menu is enabled in your theme options. Then, add this to your child theme’s style.css:


@media only screen and (max-width: 768px) {
.mobile_header {
display: block;
}
.navbar-toggle {
display: block;
}
.navbar-collapse.collapse {
display: none !important;
}
.navbar-collapse.collapse.in {
display: block !important;
}
}

Adjusting Font Sizes Responsively

Ensure your header text is readable on all devices by adjusting font sizes responsively:


@media only screen and (max-width: 768px) {
.navbar-nav > li > a {
font-size: 14px;
}
}
@media only screen and (max-width: 480px) {
.navbar-nav > li > a {
font-size: 12px;
}
}

Creating a Collapsible Search Bar

If your header includes a search bar, you might want to make it collapsible on smaller screens. Add this to your child theme’s functions.php:


function add_collapsible_search() {
if (wp_is_mobile()) {
echo '<div class="mobile-search-trigger"><i class="fas fa-search"></i></div>';
echo '<div class="mobile-search-wrapper">';
get_template_part('templates/advanced_search');
echo '</div>';
}
}
add_action('wpresidence_after_header', 'add_collapsible_search');

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


@media only screen and (max-width: 768px) {
.mobile-search-wrapper {
display: none;
position: absolute;
top: 100%;
left: 0;
right: 0;
background: #fff;
padding: 10px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.mobile-search-trigger {
display: block;
cursor: pointer;
}
}

Implementing Sticky Header for Desktop Only

You might want to use a sticky header on desktop but not on mobile. Add this to your child theme’s functions.php:


function sticky_header_script() {
if (!wp_is_mobile()) {
wp_enqueue_script('sticky-header', get_stylesheet_directory_uri() . '/js/sticky-header.js', array('jquery'), '1.0', true);
}
}
add_action('wp_enqueue_scripts', 'sticky_header_script');

Create a file named sticky-header.js in your child theme’s js folder:


jQuery(document).ready(function($) {
var header = $('.header_wrapper');
var headerOffset = header.offset().top;
$(window).scroll(function() {
if ($(window).scrollTop() > headerOffset) {
header.addClass('sticky');
} else {
header.removeClass('sticky');
}
});
});

Testing Responsiveness

After implementing these changes, thoroughly test your header on various devices and screen sizes. Use browser developer tools to simulate different screen sizes and check for any layout issues or functionality problems.

Using WordPress Customizer for Responsive Preview

Leverage the WordPress Customizer for live previews of your responsive design. Add this to your child theme’s functions.php to enable responsive previews in the Customizer:


function add_responsive_previews($wp_customize) {
$wp_customize->add_section('responsive_preview', array(
'title' => __('Responsive Preview', 'wpresidence-child'),
'priority' => 200,
));
$wp_customize->add_setting('responsive_preview_setting', array(
'default' => 'desktop',
'sanitize_callback' => 'sanitize_text_field',
));
$wp_customize->add_control('responsive_preview_control', array(
'label' => __('Preview Size', 'wpresidence-child'),
'section' => 'responsive_preview',
'settings' => 'responsive_preview_setting',
'type' => 'radio',
'choices' => array(
'desktop' => __('Desktop', 'wpresidence-child'),
'tablet' => __('Tablet', 'wpresidence-child'),
'mobile' => __('Mobile', 'wpresidence-child'),
),
));
add_action('customize_register', 'add_responsive_previews');

By implementing these responsive design techniques, you can ensure that your WPResidence header looks great and functions well across all devices. Remember to always test thoroughly and make adjustments as needed to provide the best possible user experience for your real estate website visitors.

Technical how to | Custom Code RequiredWPResidence 5.0 Documentation

Related Articles

  • Webhook Integration for Contact Forms
  • Technical: Change the Schedule Tour Email Text and the Form Default Message
  • Property list filter customization
  • Technical – How to Change the Minimum Image Dimensions for Property Uploads in WPResidence

Help Categories

  • 18Agent, Agency & Developers
  • 5Blog Posts & Blog Lists
  • 38Elementor Shortcodes Built-In
  • 45FAQ
  • 15Footer
  • 5Getting Started
  • 37Header
  • 2IDX & MLSImport
  • 6Installation & Setup
  • 23Installation FAQ
  • 23Maps & Location Settings
  • 21Multi-Language - Third Party Plugins
  • 6Other Third party Plugins
  • 20Pages
  • 4Payments & Monetization
  • 20Property Lists, Categories & Archive
  • 37Property Pages & Layouts
  • 31Search & Filtering
  • 162Technical how to | Custom Code Required
  • 8Technical: Actions and filters
  • 6Technical: Child Theme
  • 86Theme Options & Global Settings
  • 7Translations & Languages
  • 16WPBakery Shortcodes
  • 50WPEstate / WPResidence Translate Plugin
  • 51WPResidence / WPEstate CRM
  • 50WPResidence 5.0 Documentation
  • 8WPResidence Elementor Studio

Join Us On

Powered by WP Estate - All Rights Reserved
  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API