Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hello I need to have the following code on a specific page:

<div class="searchbar" >

            <div class="searchbar-inner" >

                search <input type="text" id="search" />

                <span class="result-count" ></span>

            </div>

</div>

Is it possible that I use a shortcode to place it on the visual editor while editing the page?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Assuming you don't have the shortcode written down...

function search_shortcode()
{
    $struct = '<div class="searchbar" ><div class="searchbar-inner" >search <input type="text" id="search" /><span class="result-count" ></span></div></div>';
    return $struct;
}
add_shortcode('search_box', 'search_shortcode');

Make sure your editor is in the 'HTML' mode, and paste the shortcode as 'search_box'. Using a shortcode will allow you to reuse this form anywhere you want.

share|improve this answer
    
thanks! just want to ask, why do you need it to be added on the variable $struct? can't it be echo '<div class=....' instead? –  Laurize Oct 5 '11 at 1:08
    
Yes you can, like return '<div class=...'! $struct is just a variable to hold the entire mark up string. You can name it anything you like and return it, or even return the markup string directly! –  Rutwick Gangurde Oct 5 '11 at 3:54
    
Thanks! it seems it's easier to have a variable. :) –  Laurize Oct 5 '11 at 5:58
    
Right! You're welcome! –  Rutwick Gangurde Oct 5 '11 at 6:02

Yes, you can use shortcode, but its not necessary.

You can switch to the HTML tab (next to the visual tab) in the post editor and paste your code there.

Also you should format your search input like the one below if you're planning to adhere the WordPress search rules.

<div class="searchbar">
    <div class="searchbar-inner">
        <form action="http://example-site-name.tld/" method="get">
            <label for="search">Search</label><input id="search" type="text" name="s" />
        </form>
        <span class="result-count"> </span>
    </div>
</div>

Cheers,

share|improve this answer

Your Answer

 
discard

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.