How to create a search box inside page in WordPress
Do you want to create a search box inside page for your website which is running in WordPress ?
Here is the easy solution
Step 1: Create new page . At left hand side click on page >> Add New
Step 2 : Give the title of page “Search”
Step 3: Click on text tab at right hand side top corner . Write down the given below code
Note: Replace https://sharadchhetri.com/?s= with your website link like this http://yourwebsite.com/?s=
Replace value=”Search” in code
<strong>Search Your Topic From Here</strong>
<br><form method=”get” id=”searchform” action=”https://sharadchhetri.com/?s=”/>
<input type=”text” size=”40″ name=”s” id=”s” value=”Search Linux …” onfocus=”if(this.value==this.defaultValue)this.value=”;” onblur=”if(this.value==”)this.value=this.defaultValue;”/>
<br>
<input type=”submit” id=”searchsubmit” value=”Search” />
</form>
Step 4: Now click on Publish button and see the result.
It damaged the WordPress page.
I had to delete and then recreate the page to revcover the Website
Not recommended.
Thank u it works
Hello Sharad,
I am a newbie to word press.Please help me to solve this- I want to add a search box in a particular page of my website from where when user can search the accurate thing, for example what i want to do is there are scanned images of documents with a 4 digit unique numbers like 8888,3456 in a page where i had uploaded them which i don’t want to show publicly. Now user have to put 8888 in the search field and it should get the accurate 8888 name of image from that page where it is uploaded and if cannot found the match then it have to say that ” file not found please check the number and try again” like that.
Or please will you help me to write a script for the above scenario?
Thanks in advance.
Thank you Sharad!
I will have a look through the links you have sent.
Cheers
Lorraine
I’m new to WordPress… So am I understanding this code creates a Button? I want to basically have a page that contains archived posts for each year and I want to give the user and specific search option on each page that only searches within that year on the page.
I don’t want to screw around or remove the main site search on the right menu either.
Can you tell me if this would work or point me in a direction that I might find an answer?
Many thanks
Lorraine
Hello Loriane,
I believe you can achive this by
1. Working on archive.php page
2. Working on SQL Query . Will suggest you to read this for more understanding https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-includes/general-template.php#L0
3. You can create plugin which will select query from particular year depending upon the search excuted from particular archive page.
On our live site, I tried running with random URL, it will help you to understand (But it depends upon permalink) for eg.
https://sharadchhetri.com/2014/02/?s=linux (This will show result)
https://sharadchhetri.com/2015/02/?s=linux (This will not show result with linux keyword for 2015-Feb )
https://sharadchhetri.com/2014/02/?s=gluster (I used gluster then it shows result for 2015-Feb )
Regards
Sharad