WP Residence Help WP Residence Help

  • WPRESIDENCE
  • Video Tutorials
  • Client Support
  • API
Home / Technical how to | Custom Code Required, WPResidence 5.0 Documentation / Understanding and Using Header Actions in WPResidence

Understanding and Using Header Actions in WPResidence

558 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 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

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

Join Us On

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