WordPress.org

Support

Support » Themes and Templates » [Theme: Elbee Elgee] [PATCH] Translation support and dynamic color for search

[Theme: Elbee Elgee] [PATCH] Translation support and dynamic color for search

  • To add translation support and dynamic color for the search form, find the current contents of searchform.php:

    <?php if (!is_search()) {
    	$search_text = 'Search...';
    } else {
    	$search_text = "$s";
    }
    ?>
    
    <form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    	<input type="text" id="s" name="s" value="<?php echo esc_html($search_text, 1); ?>" onfocus="if (this.value == 'Search...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search...';}"/>
    	<input type="hidden" id="searchsubmit" value="Search" />
    </form>

    and replace them with

    <?php $default_search_text = __( 'Search' ) . '...';
    $initial_search_color = 'gray';
    if (!is_search()) {
    	$search_text = $default_search_text;
    } else {
    	$search_text = esc_html($s, 1);
    	$initial_search_color = '#000';
    }
    ?>
    <form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    	<input type="text" id="s" name="s" style="color:<?php echo $initial_search_color; ?>" value="<?php echo $search_text; ?>" onfocus="if (this.value == '<?php echo $default_search_text; ?>') {this.value = '';this.style.color = '#000';}" onblur="if (this.value == '') {this.value = '<?php echo $default_search_text; ?>';this.style.color = 'gray';}"/>
    	<input type="hidden" id="searchsubmit" value="Search" />
    </form>

    If you want to make the change update-safe, don’t replace anything in the original file, just make a new one of the same name inside your child theme’s folder with the above contents. This is intended to be suitable for inclusion in the plugin core, so if that happens, there’s no more worrying over update-safe 🙂

    After this the search form will show ‘Search…’ if English language is selected (sitewide, or by user using eg. the qTranslate language chooser), ‘Hae…’ if Finnish is selected and so forth. This default text is gray, but all user-entered text is black. This uses the shortest possible markup for the colors: ‘gray’ takes three bytes fewer than ‘#808080’, and ‘#000’ takes one byte less than ‘black’.

    After the initial submission of this post, the second code is now updated to behave properly on search pages (if you submit ‘test’, it is auto-filled, as before, but unlike before, it doesn’t get cleared away when you click the form, and it’s initially black). Also, esc_html is now called only once.

    http://wordpress.org/extend/themes/elbee-elgee/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Theme: Elbee Elgee] [PATCH] Translation support and dynamic color for search’ is closed to new replies.