Site logo

Archived topic

Enter predefined text in searchbox

10 replies · Started by xdaniel on November 8, 2015

Viewing posts 1–11 of 11

Hi Tom,

is there a way to enter some predefined text into the searchbox like "Enter your searchterm here" which will be deleted when you click into the field?

Best, Daniel

I used something like this.

Original line

<input type="text" class="textfield" name="q" size="24" />

replace with (change as required)

<input type="text" class="textfield" name="q" size="24" value ="CHANGE THIS TEXT" onfocus="if(this.value=='CHANGE THIS TEXT')this.value=''" />

You might have to play with it but don't alter the original searchform.php file

Thanks for your reply. Where shall I change it, when don't alter the original file?

Ah, are you trying to add it to the navigation search?

yes.

You can overwrite the entire function in your child theme:

if ( ! function_exists( 'generate_navigation_search' ) ) :
/**
 * Add the search bar to the navigation
 * @since 1.1.4
 */
add_action( 'generate_inside_navigation','generate_navigation_search');
function generate_navigation_search()
{
	$generate_settings = wp_parse_args( 
		get_option( 'generate_settings', array() ), 
		generate_get_defaults() 
	);
		
	if ( 'enable' !== $generate_settings['nav_search'] )
		return;
			
	?>
	<form method="get" class="search-form navigation-search" action="<?php echo esc_url( home_url( '/' ) ); ?>">
		<input type="search" placeholder="YOUR PLACEHOLDER HERE" class="search-field" value="<?php echo esc_attr( get_search_query() ); ?>" name="s" title="<?php _ex( 'Search', 'label', 'generatepress' ); ?>">
	</form>
	<?php
}
endif;

Yes that did the trick! Thousand thanks! I did it with "Code Snippets" instead of the childtheme. One more question. If I want this text white, what can I do?

Glad that worked - and thanks for posting the CSS solution :)

This archived topic is closed to new replies.