Extending WPResidence Theme with Actions and Filters – Part 2
1. Additional Actions in header_media.php
1.1 wpestate_before_header_media_content
This action is executed before the main header media content.
Usage in child theme’s functions.php:
function my_custom_before_header_media_content() {
echo '<div class="pre-header-content">Important announcement here</div>';
}
add_action('wpestate_before_header_media_content', 'my_custom_before_header_media_content');
1.2 wpestate_after_header_media_content
This action is executed after the main header media content.
Usage example:
function my_custom_after_header_media_content() {
echo '<div class="post-header-content">Check out our latest listings</div>';
}
add_action('wpestate_after_header_media_content', 'my_custom_after_header_media_content');
1.3 wpestate_before_mobile_search
This action is executed before displaying mobile search.
Usage example:
function my_custom_before_mobile_search() {
if (wp_is_mobile()) {
echo '<div class="mobile-search-tip">Tap to start your search</div>';
}
}
add_action('wpestate_before_mobile_search', 'my_custom_before_mobile_search');
1.4 wpestate_after_mobile_search
This action is executed after displaying mobile search.
Usage example:
function my_custom_after_mobile_search() {
if (wp_is_mobile()) {
echo '<div class="mobile-search-results">Your results will appear here</div>';
}
}
add_action('wpestate_after_mobile_search', 'my_custom_after_mobile_search');
2. Additional Filters in header-media-functions.php
2.1 wpestate_404_archive_header_type
This filter customizes header type for 404 and archive pages with Google Map taxonomy.
Usage example:
function my_custom_404_archive_header_type($header_type) {
if (is_404()) {
return 2; // Use image header for 404 pages
}
return $header_type;
}
add_filter('wpestate_404_archive_header_type', 'my_custom_404_archive_header_type');
2.2 wpestate_property_list_header_type
This filter customizes header type for property list pages.
Usage example:
function my_custom_property_list_header_type($header_type) {
if (is_post_type_archive('estate_property')) {
return 3; // Use theme slider for property archive
}
return $header_type;
}
add_filter('wpestate_property_list_header_type', 'my_custom_property_list_header_type');
3. Extending Theme Slider Functionality
3.1 wpestate_slider_cycle
This filter allows customization of the slider cycle time.
Usage example:
function my_custom_slider_cycle($cycle_time) {
return 7000; // Set slider cycle time to 7 seconds
}
add_filter('wpestate_slider_cycle', 'my_custom_slider_cycle');
3.2 wpestate_theme_slider_content
While not a direct filter, you can create this filter to modify the slider content.
First, in the theme slider function, add this filter:
$slider_content = apply_filters('wpestate_theme_slider_content', $default_content, $post_id);
Then in your child theme:
function my_custom_slider_content($content, $post_id) {
$custom_field = get_post_meta($post_id, 'custom_slider_text', true);
if (!empty($custom_field)) {
$content .= '<div class="custom-slider-text">' . esc_html($custom_field) . '</div>';
}
return $content;
}
add_filter('wpestate_theme_slider_content', 'my_custom_slider_content', 10, 2);
4. Customizing Header Image Display
4.1 wpestate_header_image_height
This filter allows customization of the header image height.
Usage example:
function my_custom_header_image_height($height) {
if (is_front_page()) {
return 800; // Set front page header height to 800px
}
return $height;
}
add_filter('wpestate_header_image_height', 'my_custom_header_image_height');
4.2 wpestate_header_overlay_opacity
This filter allows customization of the header overlay opacity.
Usage example:
function my_custom_header_overlay_opacity($opacity) {
if (is_single() && get_post_type() == 'estate_property') {
return 0.7; // Increase overlay opacity for single property pages
}
return $opacity;
}
add_filter('wpestate_header_overlay_opacity', 'my_custom_header_overlay_opacity');
These additional examples provide more ways to extend and customize the WPResidence theme using actions and filters in a child theme. By leveraging these hooks, you can further modify the theme’s functionality and appearance to meet specific requirements.