{"id":828,"date":"2018-03-14T13:53:30","date_gmt":"2018-03-14T08:23:30","guid":{"rendered":"http:\/\/holithemes.com\/blog\/?p=828"},"modified":"2018-03-14T13:53:30","modified_gmt":"2018-03-14T08:23:30","slug":"wordpress-search-form-as-google-custom-search-engine-search-box","status":"publish","type":"post","link":"https:\/\/holithemes.com\/blog\/wordpress-search-form-as-google-custom-search-engine-search-box\/","title":{"rendered":"Make WordPress Search Form as Google Custom Search Engine &#8211; Search box"},"content":{"rendered":"\n<p>Make The Default WordPress Search Form to search using Google Custom Search<\/p>\n\n\n\n<p>WordPress initially check for &quot;searchform.php&quot; to display the search form. ( in child theme or in parent theme )\u00a0and this search form can access using &quot;get_search_form()&quot;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"560\" height=\"315\" src=\"https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/Make-WordPress-Search-Form-as-Google-Custom-Search-Engine-Search-box-1.png\" alt=\"\" class=\"wp-image-1177\" srcset=\"https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/Make-WordPress-Search-Form-as-Google-Custom-Search-Engine-Search-box-1.png 560w, https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/Make-WordPress-Search-Form-as-Google-Custom-Search-Engine-Search-box-1-300x169.png 300w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/figure>\n\n\n\n<p>For demo purpose we are using Twenty Seventeen Theme<\/p>\n\n\n\n<p>This is the\u00a0Twenty Seventeen Theme &#8211; search form ( searchform.php )<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form role=&quot;search&quot; method=&quot;get&quot; class=&quot;search-form&quot; action=&quot;&lt;?php echo esc_url( home_url( &#x27;\/&#x27; ) ); ?&gt;&quot;&gt;\n\t&lt;label for=&quot;&lt;?php echo $unique_id; ?&gt;&quot;&gt;\n\t\t&lt;span class=&quot;screen-reader-text&quot;&gt;&lt;?php echo _x( &#x27;Search for:&#x27;, &#x27;label&#x27;, &#x27;twentyseventeen&#x27; ); ?&gt;&lt;\/span&gt;\n\t&lt;\/label&gt;\n\t&lt;input type=&quot;search&quot; id=&quot;&lt;?php echo $unique_id; ?&gt;&quot; class=&quot;search-field&quot; placeholder=&quot;&lt;?php echo esc_attr_x( &#x27;Search &amp;hellip;&#x27;, &#x27;placeholder&#x27;, &#x27;twentyseventeen&#x27; ); ?&gt;&quot; value=&quot;&lt;?php echo get_search_query(); ?&gt;&quot; name=&quot;s&quot; \/&gt;\n\t&lt;button type=&quot;submit&quot; class=&quot;search-submit&quot;&gt;&lt;?php echo twentyseventeen_get_svg( array( &#x27;icon&#x27; =&gt; &#x27;search&#x27; ) ); ?&gt;&lt;span class=&quot;screen-reader-text&quot;&gt;&lt;?php echo _x( &#x27;Search&#x27;, &#x27;submit button&#x27;, &#x27;twentyseventeen&#x27; ); ?&gt;&lt;\/span&gt;&lt;\/button&gt;\n&lt;\/form&gt;<\/code><\/pre>\n\n\n\n<p>Notice the form &#8211; &quot;action&quot; attribute &#8211; it points to the home URL, we can change this<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>action=&quot;&lt;?php echo esc_url( home_url( &#x27;\/&#x27; ) );<\/code><\/pre>\n\n\n\n<p>and then at the &quot;input&quot; field notice the name attribute &#8211; name=&quot;s&quot;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>name=&quot;s&quot;<\/code><\/pre>\n\n\n\n<p>this is the search field parameter, and this is the default search parameter for wordpress<\/p>\n\n\n\n<p>you can check this by directly entering in URL bar &#8211; &quot;youdomain.com\/?s=some-query-text<\/p>\n\n\n\n<p>Now WordPress will search for &quot;some-query-text&quot; and display result<\/p>\n\n\n\n<p>&quot;s&quot; is query paramater<\/p>\n\n\n\n<p>Google Custom Search Query default parameter is &quot;q&quot; ( can change this, but if you changed to &quot;s&quot; again default wordpress result may appear, so change to any letter other then &quot;s&quot;, &quot;p&quot;\u00a0 \u00a0)<\/p>\n\n\n\n<p>To Make the Default WordPress search form to search using Google Custom Search &#8211; <strong>Change the query parameter &quot;s&quot; to &quot;q&quot;<\/strong><\/p>\n\n\n\n<p>i.e. the &quot;input&quot; filed &quot;name&quot; attribute value will be &quot;q&quot;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>name=&quot;q&quot;<\/code><\/pre>\n\n\n\n<p>and have to add Google Custom Search Engine script in the page where the form action navigate<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>action=&quot;&lt;?php echo esc_url( home_url( &#x27;\/&#x27; ) );<\/code><\/pre>\n\n\n\n<p>here it navigates to home URL, so add Google Custom Search engine script in home page<\/p>\n\n\n\n<p>or change the form navigation URL to some other page and add Custom code engine script in that page alone.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>action=&quot;&lt;?php echo esc_url( home_url( &#x27;\/search&#x27; ) );<\/code><\/pre>\n\n\n\n<p>now create a page &quot;search&quot; and add custom search engine script in that page alone.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"643\" height=\"418\" src=\"https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/image-13.png\" alt=\"Google Custom Search Engine Code\" class=\"wp-image-446\" srcset=\"https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/image-13.png 643w, https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/image-13-300x195.png 300w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/><\/figure>\n\n\n\n<p>Now When user search on any page &#8211; it navigates to &quot;yourdomain.com\/search&quot; and will display the result using Google Custom Search Engine.<\/p>\n\n\n\n<p>In Search form if you enter &quot;nyc&quot; then the page will navigate to &quot;yourdomain.com\/search\/?q=nyc&quot;<\/p>\n\n\n\n<p>Google Custom Search Engine will get the search query term from the URL<\/p>\n\n\n\n<p>You can add the Default search form in sidebar, footer or so . . using Widgets .. which is less wait, and no need to load google script all the time. and when user search&#x27;s it will navigate to a page. and in that page alone Google custom search engine script will loads<\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<p><a href=\"https:\/\/holithemes.com\/blog\/simple-search-form-for-google-custom-search-engine\/\">Create simple Search Form for Google Custom Search Engine<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/holithemes.com\/blog\/simple-search-form-for-google-custom-search-engine\/\">Add Google Custom Search Engine in Website<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Make The Default WordPress Search Form to search using Google Custom Search WordPress initially check for &quot;searchform.php&quot; to display the search form. ( in child theme or in parent theme )\u00a0and this search form can access using &quot;get_search_form()&quot; For demo purpose we are using Twenty Seventeen Theme This is the\u00a0Twenty Seventeen Theme &#8211; search form [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[15,16,7],"tags":[],"class_list":["post-828","post","type-post","status-publish","format-standard","hentry","category-google-custom-search-engine","category-search-engine","category-wordpress"],"_links":{"self":[{"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/posts\/828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/comments?post=828"}],"version-history":[{"count":0,"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/posts\/828\/revisions"}],"wp:attachment":[{"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/media?parent=828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/categories?post=828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/tags?post=828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}