-1

I would like to add some text in my blank search box for my blog.

My Blog: www.bornsquishy.com

Current searchform.php code:

<form method="get" id="searchform" action="<?php bloginfo('home'); ?>">
    <input type="text" value="<?php the_search_query(); ?>" name="s">
   <input type="submit" value="Go">
</form>

I'm sure it's a simple fix, but I no absolutely nothing about php.

EDIT - Here's how I solved the problem:

<form method="get" id="searchform" action="<?php bloginfo('home'); ?>">
   <input type="text" placeholder="Search My Site" value="<?php the_search_query(); ?>" name="s">
   <input type="submit" value="Go">
</form>

1 Answer 1

2

From the Codex Docs: The is_search() Conditional Tag checks if search result page archive is being displayed. This is a boolean function, meaning it returns either TRUE or FALSE.

<?php $search_box_term = is_search() ? get_search_query() : 'DEFAULT SEARCHBOX STRING'; ?>
<input type="text" value="<?php echo $search_box_term; ?>" name="s">

So this ↑ shows either DEFAULT SEARCHBOX STRING or the searched terms if you´re on a search results page.


EDIT: Here´s a filter that you can drop instead into your functions.php file:

function wpse50321_alter_search_form( $form )
{
    return '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '" >
    <input type="text" value="' . ( is_search() ? get_search_query() : 'DEFAULT SEARCHBOX STRING' ) . '" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="'. esc_attr__('Go') .'" />
    </form>';
}
add_filter( 'get_search_form', 'wpse50321_alter_search_form', 99999 );
10
  • Thanks kaiser, but I'm still kinda lost. The php code I provided is what came with my theme, and I have the CSS already setup for it. Is there a way to incorporate the 'DEFAULT SEARCHBOX STRING' into the existing search box code?
    – BryGuy
    Commented Apr 26, 2012 at 14:58
  • This ↑ is adding a default text to your search box and replacing it with the search string on a search result page. The code isn´t changing css or anything else. Just the default value of the box. Add it and see what happens.
    – kaiser
    Commented Apr 26, 2012 at 15:04
  • I added the code and it created a second search box.
    – BryGuy
    Commented Apr 26, 2012 at 15:16
  • You have to replace your current search box with that. Else: You get two... EDIT See update. Now you got a filter also.
    – kaiser
    Commented Apr 26, 2012 at 15:21
  • When I remove the original code it removes my search box and leaves me with a search box with the "default..." text in it, but it doesn't do anything, and doesn't conform to my CSS.
    – BryGuy
    Commented Apr 26, 2012 at 15:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.