How to Redirect a Search Form to a Site-Scoped Google Search

How to Redirect a Search Form to a Site-Scoped Google Search 3

This is just a tiny little trick that might be helpful on a site where you don’t have the time or desire to build out a really good on-site search solution. itself can perform searches scoped to one particular site. The trick is getting people there using that special syntax without them even knowing it.

Make a search form:

<form action="" target="_blank" type="GET">

     Search CSS-Tricks on Google: 
     <input type="search" name="q">

  <input type="submit" value="Go">


When that form is submitted, we’ll intercept it and change the value to include the special syntax:

var form = document.querySelector("form");

form.addEventListener("submit", function (e) {
  var search = form.querySelector("input[type=search]");
  search.value = " " + search.value;

That’s all.

This post was originally posted here

Check out our Starter Sites built with #ToolWeLove including Toolset, Elementor Pro, and Astra Pro.


Share this page
Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on email
How to Choose WordPress Hosting

Pixallus WordPress Hosting. Simplified. Enjoy blazing fast WordPress website loading speeds and 99.9% uptime. Whether you’re a freelancer, small business, or a large organization, we

Read More »