WordPress.org

Support

Support » How-To and Troubleshooting » Change the default text in my search form?

Change the default text in my search form?

  • Hi,

    The current text in my search form is “search for..” but I would like to change it. How can I do this? Here is what’s in my searchform.php file:

    <form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    		<label for="s" class="assistive-text"><?php _e( 'Search', 'twentyeleven' ); ?></label>
    		<input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
    		<input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
    	</form>
Viewing 15 replies - 1 through 15 (of 15 total)
  • Change the value in the placeholder attribute.

    Hmmm, this is odd. According the PHP code, the place holder is “Search.” But on my website, the search from is displaying “Search..” with the two periods.

    Moderator Andrew Nevins

    @anevins

    Forum moderator

    Perhaps some JavaScript is executing this?

    @andrew Bartel

    I changed the placeholder attribute but it didn’t work.

    @andrew Nevins.

    Ok, how do I check if this is JS? My site is: http://travelgrom.com

    Moderator Andrew Nevins

    @anevins

    Forum moderator

    Can you post here the new code of your searchform.php file (with the new value attribute)?

    Nah, you’re using Purity template. Make sure you’re checking the right searchform.php file.

    @Buddykiller

    Ahhh yes you’re right. My mistake. Correction, here is the Purity Theme search form:

    <div class="search">
    	<form method="get" id="searchform" action="<?php echo home_url(); ?>/">
            <input class="search_submit" id="searchsubmit" value="" type="submit">
            <input class="search_box" name="s" id="s" type="text" value="<?php tr_translate(search); ?>" onfocus="if (this.value == '<?php tr_translate(search); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php tr_translate(search); ?>';}">
        </form>
    </div>

    However, I tried changing (search) to my custom text and when I uploaded the .php the search form appeared blank…

    Please help!

    Copy paste the code here please. I’ve done this myself, you gotta check javascript too because it will lead to a blank input field.

    @buddykiller

    the code is pasted in my last post. Which JS file should I check?

    /wp-content/themes/purity/js/contact-form.js
    /wp-content/themes/purity/js/custom.js
    /wp-content/themes/purity/js/jquery.easing.js
    /wp-content/themes/purity/js/jquery.nivo.slider.pack.js
    /wp-content/themes/purity/js/jquery.prettyPhoto.js
    /wp-content/themes/purity/js/jquery.quicksand.min.js
    /wp-content/themes/purity/js/portfolio-height.js

    when I inspect the search bar in Chrome it’s linking to this: <input class=​”search_box” name=​”s” id=​”s” type=​”text” value=​”Search..” onfocus=​”if (this.value == ‘Search..’)​ {this.value = ”;​}​” onblur=​”if (this.value == ”)​ {this.value = ‘Search..’;​}​”>​

    Does this show where the info is being pulled from?

    Please help!

    Moderator Andrew Nevins

    @anevins

    Forum moderator

    You ought to leave that Javascript, it’s saying if your search input field has no value, it sets it as ‘Search..’.

    So your search value is empty.

    @andrew nevins

    So what would I do to this searchform.php if I want to customize the text

    div class="search">
    	<form method="get" id="searchform" action="<?php echo home_url(); ?>/">
            <input class="search_submit" id="searchsubmit" value="" type="submit">
            <input class="search_box" name="s" id="s" type="text" value="<?php tr_translate(search); ?>" onfocus="if (this.value == '<?php tr_translate(search); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php tr_translate(search); ?>';}">
        </form>
    </div>
    Moderator Andrew Nevins

    @anevins

    Forum moderator

    What does the function tr_translate() do?

    syrinx32123 you have a wootheme template no ?
    Anyway, if you don’t maintain multiple website on your wordpress installation, you could remove the tr_translate function and simply write what you want inside this search form.
    Make it match with the Javascript so that when you click on the search form, it erase the content.

    If you want something clean, you’ll have to check that tr_translate function in “admin-functions.php” or another file and see if you have a result for “search” in that tr_translate function. It seems it translates to nothing at the end, leaving a “” field.

    Thank you @andrew Nevins & @buddykiller.

    I have resolved the issue with your help.

    For anyone else with the same problem, reference this site:

    Getting Text in your WordPress Search Box

    The only curious thing is that I have to upload the search.php into my main theme file… it won’t work when uploaded to my child theme folder

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Change the default text in my search form?’ is closed to new replies.
Skip to toolbar