Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #3969

    Hello. I would like to add the default text “Search…” inside the search field.

    I noticed the header.php file uses the get_search_form to call the search form, so I tried modifying the value tag in the searchform.php file from this:

    <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
    <div><input type="text" class='rounded text_input' value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
    <input type="submit" class="button ie6fix" id="searchsubmit" value="." />
    </div>
    </form>

    to this:

    <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
    <div><input type="text" class='rounded text_input' value="Search..." name="s" id="s" />
    <input type="submit" class="button ie6fix" id="searchsubmit" value="." />
    </div>
    </form>

    but it didn’t work. Is there somewhere else I should be looking for?

    Thanks!

    #44400

    Hey,

    try this code – I tested it and it worked…

    <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
    <div><input type="text" class='rounded text_input' value="<?php echo wp_specialchars($s, 1); ?>Search..." name="s" id="s" />
    <input type="submit" class="button ie6fix" id="searchsubmit" value="." />
    </div>
    </form>

    #44401

    Hi Dude,

    Thanks for your help: it worked like a charm. I am guessing the reason it didn’t work in my example was because I deleted

    <?php echo wp_specialchars($s, 1); ?>

    What does that piece of code do, and why is it necessary to force the display of the text in the theme’s search bar?

    Thanks!

    #44402

    Basically the function just converts html tags to text: http://codex.wordpress.org/Function_Reference/wp_specialchars – I’m not sure why it effects the search value if you replace it with “Search…” though.

    #44403

    That makes a lot of sense indeed. Then the reason why the search value gets affected is probably related to the fact that the searchform.php is mostly html code called from a php file, so the double quotes need to be escaped before passing the value of the input field.

    I should of thought of that earlier. Sorry for that, and thanks for your help.

    #44404

    Glad that I could help you :)

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘How to add default search text to search field on Newscast?’ is closed to new replies.