This hook in WP Maps Pro allows developers to customize the functionality at runtime by changing the position of the filters container. It is specifically used to modify the data container identified by [data-container="wpgmp-filters-container"]
and accepts parameters such as '[data-container="wpgmp-filters-container"]'
and $map
.
Usage
Developers can implement this hook in their WordPress themes or plugins to alter the position of the filters container dynamically. This can be particularly useful when needing to integrate WP Maps Pro with other components or when requiring custom layouts.
Example 1
In this example, the hook is used to append additional classes to the filters container, potentially for styling purposes.
add_filter( 'wpgmp_filter_container', 'customize_filters_container', 10, 2 ); function customize_filters_container( $container, $map ) { $container .= ' custom-class'; return $container; }
Example 2
This example demonstrates how to move the filters container to a different location in the DOM, by using JavaScript to reposition it.
add_filter( 'wpgmp_filter_container', 'move_filters_container', 10, 2 ); function move_filters_container( $container, $map ) { $container = "<script type='text/javascript'> document.addEventListener('DOMContentLoaded', function() { var filtersContainer = document.querySelector('[data-container=\"wpgmp-filters-container\"]'); var newParent = document.getElementById('new-location'); if (filtersContainer && newParent) { newParent.appendChild(filtersContainer); } }); </script>"; return $container; }
Example 3
Here, the hook is used to inject custom content or HTML before the filters container, which might be useful for adding labels or instructions.
add_filter( 'wpgmp_filter_container', 'add_content_before_filters', 10, 2 ); function add_content_before_filters( $container, $map ) { $custom_content = '<div class="custom-content">Before Filters Content</div>'; $container = $custom_content . $container; return $container; }
Tip: Always ensure that any custom code or scripts added through hooks are thoroughly tested to prevent breaking the layout or functionality of the WP Maps Pro plugin. Additionally, consider using WordPress’s built-in security functions to sanitize and validate data.