[Resolved] Enter predefined text in searchbox

Home Forums Support [Resolved] Enter predefined text in searchbox

Home Forums Support Enter predefined text in searchbox

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #151278
    xdaniel

    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

    #151296
    tenchystryder

    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

    #151337
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Give this function a try:

    add_filter('generate_search_placeholder','generate_custom_search_placeholder');
    function generate_custom_search_placeholder() 
    {
          return 'Enter your search term here';
    }

    Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/

    #151338
    xdaniel

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

    #151342
    xdaniel

    @Tom: Sorry, this does not work. Have a look at: http://www.beb-ev.de

    #151348
    Tom
    Lead Developer
    Lead Developer

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

    #151349
    xdaniel

    yes.

    #151358
    Tom
    Lead Developer
    Lead Developer

    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;
    #151366
    xdaniel

    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?

    #151371
    xdaniel
    #151446
    Tom
    Lead Developer
    Lead Developer

    Glad that worked – and thanks for posting the CSS solution 🙂

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