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 / Understanding and Using Header Actions in WPResidence

Understanding and Using Header Actions in WPResidence

288 views 0

WPResidence provides a robust system of action hooks that allow developers to customize various aspects of the theme, including the header. These action hooks offer a powerful way to add, remove, or modify content without directly editing core theme files. This guide will explore how to effectively use header actions in WPResidence.

What Are Action Hooks?

Action hooks are specific points in the theme’s code where you can “hook” your own functions. They allow you to add custom content or functionality at precise locations without modifying the theme’s core files.

Key Header Actions in WPResidence

WPResidence offers several action hooks specific to the header area. Here are some of the most commonly used ones:

  1. wpresidence_before_header – Executes before the header
  2. wpresidence_after_header – Executes after the header
  3. wpresidence_before_logo_header – Executes before the logo in the header
  4. wpresidence_after_logo_header – Executes after the logo in the header
  5. wpresidence_before_main_menu – Executes before the main navigation menu
  6. wpresidence_after_main_menu – Executes after the main navigation menu

Using Header Actions

To use these actions, you’ll need to add custom functions to your child theme’s functions.php file. Here’s the basic structure:


function my_custom_header_function() {
// Your custom code here
}
add_action('wpresidence_action_name', 'my_custom_header_function');

Practical Examples

1. Adding a Notice Bar Above the Header


function add_notice_bar() {
echo '<div class="notice-bar">Welcome to our site! Check out our latest listings.</div>';
}
add_action('wpresidence_before_header', 'add_notice_bar');

2. Inserting a Search Bar After the Logo


function add_header_search() {
echo '<div class="header-search">';
get_search_form();
echo '</div>';
}
add_action('wpresidence_after_logo_header', 'add_header_search');

3. Adding Social Media Icons Before the Main Menu


function add_social_icons() {
echo '<div class="header-social-icons">';
echo '<a href="#"><i class="fab fa-facebook"></i></a>';
echo '<a href="#"><i class="fab fa-twitter"></i></a>';
echo '<a href="#"><i class="fab fa-instagram"></i></a>';
echo '</div>';
}
add_action('wpresidence_before_main_menu', 'add_social_icons');

Removing Default Actions

Sometimes you may want to remove default content added by WPResidence. You can do this using the remove_action() function:


function remove_default_header_content() {
remove_action('wpresidence_after_header', 'wpresidence_header_phone', 10);
}
add_action('init', 'remove_default_header_content');

Changing Action Priority

You can control the order in which actions are executed by specifying a priority. Lower numbers execute earlier:


add_action('wpresidence_before_header', 'my_function', 5); // Executes early
add_action('wpresidence_before_header', 'another_function', 15); // Executes later

Conditional Actions

You can make your header additions conditional based on various factors:


function conditional_header_content() {
if (is_front_page()) {
echo '<div class="welcome-message">Welcome to our homepage!</div>';
} elseif (is_singular('property')) {
echo '<div class="property-header-notice">Viewing a property listing</div>';
}
}
add_action('wpresidence_after_header', 'conditional_header_content');

Creating Your Own Action Hooks

While WPResidence provides many useful hooks, you might want to create your own for more specific customizations. Here’s how you can do that in your child theme:


function my_custom_header_area() {
do_action('my_custom_header_hook');
}
add_action('wpresidence_after_header', 'my_custom_header_area');

Now you can use this custom hook in your functions.php:


function add_to_custom_header() {
echo '<div class="my-custom-header-content">Custom content here</div>';
}
add_action('my_custom_header_hook', 'add_to_custom_header');

Best Practices

  1. Always use a child theme for customizations
  2. Prefix your function names to avoid conflicts
  3. Use conditional tags to target specific pages or post types
  4. Be mindful of performance – don’t add unnecessary code to every page load
  5. Test thoroughly after adding new actions, especially with different screen sizes

By leveraging these action hooks, you can extensively customize the WPResidence header to meet your specific needs without modifying core theme files. This approach ensures that your customizations remain intact even when the theme is updated.

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