WordPress.org

Ready to get started?Download WordPress

Forums

Change the default text in my search form? (16 posts)

  1. syrinx32123
    Member
    Posted 1 year ago #

    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>
  2. Andrew Bartel
    Member
    Posted 1 year ago #

    Change the value in the placeholder attribute.

  3. syrinx32123
    Member
    Posted 1 year ago #

    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.

  4. Andrew
    Forum Moderator
    Posted 1 year ago #

    Perhaps some JavaScript is executing this?

  5. syrinx32123
    Member
    Posted 1 year ago #

    @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

  6. Andrew
    Forum Moderator
    Posted 1 year ago #

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

  7. budykiller
    Member
    Posted 1 year ago #

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

  8. syrinx32123
    Member
    Posted 1 year ago #

    @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!

  9. budykiller
    Member
    Posted 1 year ago #

    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.

  10. syrinx32123
    Member
    Posted 1 year ago #

    @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

  11. syrinx32123
    Member
    Posted 1 year ago #

    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!

  12. Andrew
    Forum Moderator
    Posted 1 year ago #

    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.

  13. syrinx32123
    Member
    Posted 1 year ago #

    @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>
  14. Andrew
    Forum Moderator
    Posted 1 year ago #

    What does the function tr_translate() do?

  15. budykiller
    Member
    Posted 1 year ago #

    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.

  16. syrinx32123
    Member
    Posted 1 year ago #

    Thank you @andrew Nevins & @buddykiller.

    I have resolved the issue with your help.

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

    http://bavotasan.com/2008/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

Topic Closed

This topic has been closed to new replies.

About this Topic