• Hello,

    I’ve been trying to put a search form in a header.

    In order to not touch the general-template.php file, I’ve set up a searchform.php in my template as follow:

    <div id="searchform">
    	<form method="get" action="<?php bloginfo('url'); ?>/">
    		<p>
    			<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
    			<input type="submit" id="searchsubmit" value="Rechercher" />
    		</p>
    	</form>
    </div>

    In my style.css, I’ve got:

    [CSS moderated as per the Forum Rules. Please just post a link to your site.]

    And in my header, I’m calling the search the following way: <?php get_search_form(); ?>

    It’s nearly working …
    My search box gets duplicated in my header … I have no idea why !

    If I use Firebug and the ‘inspect element’, I can select the search box on the top. I can’t select the second one …

    Any idea where the problem could come from ?

    A screenshot available here

    Thanks for reading

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter salmoliv

    (@salmoliv)

    I’ve been trying to use a different method.

    In the functions.php, I’ve added:

    /* Custom searchform */
    function chateaurenault_search_form( $form ) {
    
        $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
        <p>
        <input type="text" value="' . get_search_query() . '" name="s" id="s" />
        <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
        </p>
        </form>';
    
        return $form;
    }
    
    add_filter( 'get_search_form', 'chateaurenault_search_form' );

    In the header, I hae: <?php chateaurenault_search_form(); ?>

    But I’m receiving an error:
    Warning: Missing argument 1 for chateaurenault_search_form(), …

    Why?
    How do you call a ‘custom’ function?

    Thanks

    Thread Starter salmoliv

    (@salmoliv)

    Ok, managed to find out what was wrong.
    The primary widget had a search form too …

    I could see it but not enter anything in the searchbox – I guess – because the header image had a higher z-index …

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘search form in header get duplicated’ is closed to new replies.