Change Trip Search Placeholder

Homepage Forums WP Travel Pro Change Trip Search Placeholder

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #24654
    joshk
    Participant

    The Trip search bar placeholder says “Ex: Trekking”.
    How can we change that to something else?
    We have a child theme and can place something in the functions.php file, if that helps.

    #24662
    wensolutions
    Keymaster

    Hello @joshk,

    Yes, you can definitely change the placeholder but for this, you need to activate your child theme.

    To know how you can create and activate the child theme, please refer to below given link:

    https://wptravel.io/how-to-create-a-child-theme/

    After activating the child theme, in your child theme functions.php add below given code:

    function wp_travel_modify_placeholder_text( $content ){
    		$label_string = apply_filters(
    			'wp_travel_search_filter_label_strings',
    			array(
    				'search'    => __( 'Search:', 'wp-travel' ),
    				'trip_type' => __( 'Trip Type:', 'wp-travel' ),
    				'location'  => __( 'Location:', 'wp-travel' ),
    			)
    		);
    	
    		$search_string    = ! empty( $label_string['search'] ) ? $label_string['search'] : '';
    		$trip_type_string = ! empty( $label_string['trip_type'] ) ? $label_string['trip_type'] : '';
    		$location_string  = ! empty( $label_string['location'] ) ? $label_string['location'] : '';
    		ob_start(); ?>
    		<div class="wp-travel-search">
    			<form method="get" name="wp-travel_search" action="<?php echo esc_url( home_url( '/' ) ); ?>" >
    				<input type="hidden" name="post_type" value="<?php echo esc_attr( WP_TRAVEL_POST_TYPE ); ?>" />
    				<p>
    					<label><?php echo esc_html( $search_string ); ?></label>
    					<?php $placeholder = __( 'Your Text', 'wp-travel' ); ?>
    					<input type="text" name="s" id="s" value="<?php echo ( isset( $_GET['s'] ) ) ? esc_textarea( $_GET['s'] ) : ''; ?>" placeholder="<?php echo esc_attr( apply_filters( 'wp_travel_search_placeholder', $placeholder ) ); ?>">
    				</p>
    				<p>
    					<label><?php echo esc_html( $trip_type_string ); ?></label>
    					<?php
    					$taxonomy = 'itinerary_types';
    					$args     = array(
    						'show_option_all' => __( 'All', 'wp-travel' ),
    						'hide_empty'      => 0,
    						'selected'        => 1,
    						'hierarchical'    => 1,
    						'name'            => $taxonomy,
    						'class'           => 'wp-travel-taxonomy',
    						'taxonomy'        => $taxonomy,
    						'selected'        => ( isset( $_GET[ $taxonomy ] ) ) ? esc_textarea( $_GET[ $taxonomy ] ) : 0,
    						'value_field'     => 'slug',
    					);
    	
    					wp_dropdown_categories( $args, $taxonomy );
    					?>
    				</p>
    				<p>
    					<label><?php echo esc_html( $location_string ); ?></label>
    					<?php
    					$taxonomy = 'travel_locations';
    					$args     = array(
    						'show_option_all' => __( 'All', 'wp-travel' ),
    						'hide_empty'      => 0,
    						'selected'        => 1,
    						'hierarchical'    => 1,
    						'name'            => $taxonomy,
    						'class'           => 'wp-travel-taxonomy',
    						'taxonomy'        => $taxonomy,
    						'selected'        => ( isset( $_GET[ $taxonomy ] ) ) ? esc_textarea( $_GET[ $taxonomy ] ) : 0,
    						'value_field'     => 'slug',
    					);
    	
    					wp_dropdown_categories( $args, $taxonomy );
    					?>
    				</p>
    	
    				<p class="wp-travel-search"><input type="submit" name="wp-travel_search" id="wp-travel-search" class="button button-primary" value="<?php esc_html_e( 'Search', 'wp-travel' ); ?>"  /></p>
    			</form>
    		</div>
    <?php
    	return ob_get_clean();
    }
     add_filter('wp_travel_search_form','wp_travel_modify_placeholder_text');

    Now, go line ” <?php $placeholder = __( ‘Your Text’, ‘wp-travel’ ); ?>” and change the text as per your requirment.

    Hope this helps.

    Thank you.

    #24724
    joshk
    Participant

    Perfect, thank you. It worked.

    #24729
    wensolutions
    Keymaster

    Hello @joshk,

    Glad we could help you.

    If you have any issues further then kindly let us know.

    Thank you.

    #24927
    joshk
    Participant

    This worked great, but then I realized that it does not allow me to translate the text in WPML string translation anymore.

    If I set the placeholder to “Food”, it sets that as the placeholder for all languages and I cannot seem to access it inside of WPML string translation to translate it.

    How do I get it to show up in WPML string translation so that I can translate it?

    #24933
    wensolutions
    Keymaster

    Hello @joshk,

    The string that you have replaced should at first be scanned using the WPML plugin as it is newly added string in the plugin.

    To scan the string you need to go to Admin Panel > WPML > Theme and Plugin Localization. Here find the text domain, click on the box and click on “Scan Selected theme For string” or “Scan Selected theme For string” button finding weather the string comes from the theme or the plugin originally.

    Screenshot:

    https://prnt.sc/rn3kph

    Hope this helps.

    Thank you.

    #25010
    joshk
    Participant

    Excellent, thank you! Worked perfectly.

    #25028
    wensolutions
    Keymaster

    Hello @joshk,

    Glad we could help.

    Let us know if you have any issues further.

    Thank you.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.