This hook in the WP Maps Pro plugin allows developers to customize the placeholder text for the search input field at runtime.
Usage
Developers can implement this hook in their theme’s functions.php file or a custom plugin. It allows for dynamic customization of the search box placeholder text, enhancing user experience by providing context-specific instructions.
Example 1
Change the placeholder text to a more descriptive prompt for a restaurant search map.
add_filter( 'wpgmp_searchbox_placeholder', function( $text ) { return esc_html__( 'Search for restaurants...', 'wpgmp-google-map' ); });
Example 2
Modify the placeholder text based on user roles, providing administrators with a different message.
add_filter( 'wpgmp_searchbox_placeholder', function( $text ) { if ( current_user_can( 'administrator' ) ) { return esc_html__( 'Admin: Enter location...', 'wpgmp-google-map' ); } return esc_html__( 'Type here...', 'wpgmp-google-map' ); });
Example 3
Set a placeholder text that changes based on the time of day, offering a personalized experience.
add_filter( 'wpgmp_searchbox_placeholder', function( $text ) { $hour = date('H'); if ( $hour < 12 ) { return esc_html__( 'Good morning! Where to?', 'wpgmp-google-map' ); } elseif ( $hour < 18 ) { return esc_html__( 'Good afternoon! Search your destination...', 'wpgmp-google-map' ); } else { return esc_html__( 'Good evening! Find a place...', 'wpgmp-google-map' ); } });
Always ensure that any custom text is properly sanitized using esc_html__()
for security and to prevent potential XSS vulnerabilities.