Extending WPResidence Theme with Actions and Filters
1. Actions in header_media.php
1.1 wpestate_before_header_media
This action is executed before the header media section begins.
Usage in child theme’s functions.php:
function my_custom_before_header_media() {
echo '<div class="custom-header-top">Custom content before header media</div>';
}
add_action('wpestate_before_header_media', 'my_custom_before_header_media');
1.2 wpestate_before_advanced_search
This action is executed before the advanced search is displayed.
Usage example:
function my_custom_before_advanced_search() {
if (is_front_page()) {
echo '<div class="search-intro">Find your dream property</div>';
}
}
add_action('wpestate_before_advanced_search', 'my_custom_before_advanced_search');
1.3 wpestate_after_advanced_search
This action is executed after the advanced search is displayed.
Usage example:
function my_custom_after_advanced_search() {
echo '<div class="search-tips">Need help? Check our search tips</div>';
}
add_action('wpestate_after_advanced_search', 'my_custom_after_advanced_search');
2. Filters in header-media-functions.php
2.1 wpestate_header_type
This filter allows modification of the header type for any page.
Usage example to force a specific header type for a certain page:
function my_custom_header_type($header_type, $post_id) {
if ($post_id == 123) { // Replace with your specific page ID
return 2; // Force image header type
}
return $header_type;
}
add_filter('wpestate_header_type', 'my_custom_header_type', 10, 2);
2.2 wpestate_global_header_type
This filter allows customization of the global header type for non-archive pages.
Usage example to change the global header type:
function my_custom_global_header_type($global_header_type) {
if (is_front_page()) {
return 3; // Use Revolution Slider for front page
}
return $global_header_type;
}
add_filter('wpestate_global_header_type', 'my_custom_global_header_type');
2.3 wpestate_header_media_class
This filter allows modification of the header media CSS class.
Usage example to add a custom class:
function my_custom_header_media_class($class) {
return $class . ' my-custom-header-class';
}
add_filter('wpestate_header_media_class', 'my_custom_header_media_class');
3. Extending Theme Slider Functionality
3.1 wpestate_theme_slider_contact
While not a direct action or filter, this function can be overridden in a child theme to customize the contact section in the theme slider.
Example of overriding in child theme’s functions.php:
function wpestate_theme_slider_contact($propid) {
// Custom implementation
$output = '<div class="custom-slider-contact">';
$output .= '<h3>Contact Agent</h3>';
$output .= '<a href="' . get_permalink($propid) . '#contact">Inquire Now</a>';
$output .= '</div>';
return $output;
}
4. Customizing Header Image Display
4.1 Overriding wpestate_header_image function
While not a direct filter, you can completely override the header image display by redefining the function in your child theme.
Example in child theme’s functions.php:
function wpestate_header_image($image) {
global $post;
if (is_single() && get_post_type() == 'estate_property') {
// Custom header for single property pages
$property_id = get_the_ID();
$header_image = get_post_meta($property_id, 'property_custom_header', true);
if (!empty($header_image)) {
echo '<div class="property-custom-header" style="background-image:url(' . esc_url($header_image) . ')"></div>';
return;
}
}
// Fall back to parent theme's implementation for other cases
include_once(get_template_directory() . '/header-media-functions.php');
wpestate_header_image($image);
}
5. Customizing Theme Slider
5.1 wpestate_theme_slider_height
This filter allows customization of the theme slider height.
Usage example:
function my_custom_slider_height($height) {
return 600; // Set slider height to 600px
}
add_filter('wpestate_theme_slider_height', 'my_custom_slider_height');
These examples demonstrate various ways to extend and customize the WPResidence theme using actions, filters, and function overrides in a child theme. By leveraging these hooks, you can significantly alter the theme’s functionality and appearance without modifying the parent theme files directly.