How To Insert A Search Box Using HTML / PHP Code In WordPress

It’s pretty easy to insert a search box in WordPress as a widget, but you can save some screen real estate if you insert a search box into your theme header (or other location) using HTML / PHP code. Also, it can be nice from a design point of view to insert a search box into another location in your theme, rather than the widget area. To insert a search box into your WordPress theme header, insert the following code into your header.php file:

<form method=”get” id=”searchform” action=”<?php bloginfo(‘home’); ?>/”>
<div><input type=”text” size=”18″ value=”<?php echo wp_specialchars($s, 1); ?>” name=”s” id=”s” />
<input type=”submit” id=”searchsubmit” value=”Search” />

This will put a searchbox on your WordPress site, next you need to put the following CSS code into the stylesheet file for your theme:

#searchform {
  position: relative;
  left: 50px;
  top: 32px;

You can then change the values of the left and top properties to move the search box around the screen. Think of them as x, y co-ordinates for placing your search box code.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)

Leave a comment

Your email address will not be published. Required fields are marked *