• syrinx32123

    (@syrinx32123)


    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)
  • Andrew Bartel

    (@andrew-bartel)

    Change the value in the placeholder attribute.

    Thread Starter syrinx32123

    (@syrinx32123)

    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.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Perhaps some JavaScript is executing this?

    Thread Starter syrinx32123

    (@syrinx32123)

    @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: https://travelgrom.com

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

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

    budykiller

    (@budykiller)

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

    Thread Starter syrinx32123

    (@syrinx32123)

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

    budykiller

    (@budykiller)

    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.

    Thread Starter syrinx32123

    (@syrinx32123)

    @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

    Thread Starter syrinx32123

    (@syrinx32123)

    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!

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    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.

    Thread Starter syrinx32123

    (@syrinx32123)

    @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>
    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    What does the function tr_translate() do?

    budykiller

    (@budykiller)

    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.

    Thread Starter syrinx32123

    (@syrinx32123)

    Thank you @andrew Nevins & @buddykiller.

    I have resolved the issue with your help.

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

    https://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

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