• HomeGo Home
  • AboutThen & Now
  • PortfolioRecent Projects
  • BlogDiscussion
  • ContactGive Me A Call
Glen Wheeler Web Developer and Motorsport Fan

Web Designer and Developer

Categories

  • Latest Articles (3)
  • Web Development (3)

Archives

  • January 2012
  • December 2011

« Post DIBI 2011 Conference

Editing WordPress Post Revisions »

Adding Value To Search In WordPress 3.0

By glenwheeler | Published January 3, 2012
wpcode

So this evening I spent some of my time styling my site and doing bit’s and bobs with the elements of WordPress 3.0.1. The new version of wordpress comes default with a theme named “twentyten” which does not use the searchform.php file which means the theme cannot be edited using the themes editor in the Content Management System backend it’s self.

Instead WordPress will render its built-in search form by calling it using the function. To edit the forms appearance we can simply use the style sheet using .widget_search #s and input[type="text"].

OK, now to and add the value to the search box. You can do this by editing the default wordpress file general-template.php, which can be found in wp-includes/general-template.php. Once you find the file, open it up in a simple text editor or software package such as adobe Dreamweaver to edit the code.

To edit the search form we are looking for the following block of code:

$form = '<form role="search" pmethod="get" id="searchform" action="'
. home_url( '/' ) . '" > <div><label for="s">' . __('Search for:') . '
</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
< /div>

</form>';

To add a value to the search box simply remove the value “.get_search_query().” and replace the value with what ever you would like it to be, for mine I changed it to “Type here & Hit Enter…” you can see the change in code below.

$form = '

<form id="searchform" action="' . home_url( '/' ) . '" method="get">
<div><label for="s">' . __('Search for:') . '</label>

<input id="s" name="s" type="text" value="Type Here &amp; Hit Enter..." />
<input id="searchsubmit" type="submit" value="'. esc_attr__('Search') .'" />
</div>
</form>';

This complete’s the editing of the file, you can now save the file and upload it to your server replacing the original general-template.php with your newly edited one, having access to this form code will also allow you to add custom class’s for more bespoke styling. Thanks for reading.

This article was posted in Latest Articles, Web Development and tagged Wordpress, Wordpress3, WP3. Bookmark the permalink. Follow comments with the RSS feed for this post.Comments are closed, but you can leave a trackback: Trackback URL.

« Post DIBI 2011 Conference

Editing WordPress Post Revisions »

© 2012 Glen Wheeler Web Developer and Motorsport Fan. All Rights Reserved. Site By: Engine