WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I entered this code in my footer widget, and the search box finally showed up:

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

But when I run a search, a <? gets appended to the query, resulting in a page not found error. Even removing the <? doesn't bring me to a results page.

To me, the php code appears ok. I doublechecked and have searchform.php in the same folder as the rest of my page templates.

This is on http://dsiinfo.webfactional.com

I've done several searches and have spent a couple of hours and this but can't figure out what's causing the problem. Thanks!

share|improve this question
Do you really use type=”text” with curly quotes? – toscho Mar 21 '13 at 21:33
What's that: action="<?php bloginfo('home'); ?>/"> ? Hint: The MarkUp colors does tell you if something is wrong. – kaiser Mar 21 '13 at 21:58
I just copied and pasted, I don't know how they showed up as curly quotes. – MMC Mar 21 '13 at 22:28

The form in your HTML code looks like this:

<form method="get" id="searchform" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <label class="hidden" for="s"><?php _e('Search this site:'); ?></label>
    <input type="text" value="Search site" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="Search" />

PHp is not parsed in this fragment, so I guess you didn't include a PHP file, just regular HTML. Put the search form code in a PHP file.

You could for example add a function like this to your functions.php:

function t5_search_form( $args = array () )
    $defaults = array (
        'form_id'  => 'searchform',
        'name'     => 's',
        'charset'  => get_bloginfo( 'charset' ),
        'label'    => esc_attr__( 'Search', 't5_theme' ),
        'action'   => site_url(),
        'value'    => esc_attr(
            apply_filters( 'the_search_query', get_search_query( FALSE ) )
        'submit'   => esc_attr__( 'Search', 't5_theme' ),
        'template' => '
        <form role="search" id="%1$s" accept-charset="%2$s" action="%8$s">
        <label for="%3$s">%4$s</label>
        <input type="search" name="%3$s" id="%3$s" value="%5$s" aria-required="true" required%6$s>
        <input type="submit" value="%7$s">
        'print' => TRUE

    $options = array_merge( $defaults, $args );
    $options = apply_filters( 't5_searchform', $options );
    extract( $options );
    $autofocus = ( is_search() and 0 === (int) $GLOBALS["wp_query"]->found_posts )
    ? ' autofocus' : '';

    $form = sprintf(

    $print and print $form;
    return $form;

… and call that function wherever you need it with t5_search_form();.

Also, don't use $_SERVER['PHP_SELF'];, use echo home_url(); instead.

share|improve this answer
Hi toscho, thanks for the quick reply. I added your code to functions.php and tried t5_search_form(); 2 ways: embedded in php tags, eg <?php t5_search_form(); ?>, which doesn't show the search box on screen; and just putting t5_search_form(); in my search div in my footer text widget. That just outputs the text t5_search_form(); to the screen. I know i'm missing something very fundamental from my understanding. – MMC Mar 21 '13 at 22:26
@MMC Wait, you put the PHP code in a Widget in the backend? That cannot work, PHP is not allowed there. – toscho Mar 22 '13 at 8:55
I did, though when I removed it and inserted just the form code, the form displays in the footer. Any ideas? I'll keep researching in the meantime. Thanks for your help so far. – MMC Mar 22 '13 at 13:54
I'm looking into using z-index to have the search box floating on top of the center of the footer since PHP isn't allowed in there. – MMC Mar 22 '13 at 19:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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