{"id":974,"date":"2018-03-14T17:15:40","date_gmt":"2018-03-14T11:45:40","guid":{"rendered":"http:\/\/holithemes.com\/blog\/?p=974"},"modified":"2018-03-14T17:15:40","modified_gmt":"2018-03-14T11:45:40","slug":"simple-search-form-for-google-custom-search-engine","status":"publish","type":"post","link":"https:\/\/holithemes.com\/blog\/simple-search-form-for-google-custom-search-engine\/","title":{"rendered":"Create simple Search Form for Google Custom Search Engine"},"content":{"rendered":"\n<p>Create Simple Search Form For Google Custom Search Engine.\u00a0<\/p>\n\n\n\n<p>A simple search form, less wait. and no need to load any dependencies to display a search form<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"1280\" height=\"720\" src=\"https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/image-14.png\" alt=\"simple search form\" class=\"wp-image-1171\" srcset=\"https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/image-14.png 1280w, https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/image-14-300x169.png 300w, https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/image-14-1024x576.png 1024w, https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/image-14-768x432.png 768w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=&quot;ht_search_form&quot;&gt;\n&lt;form action=&quot;https:\/\/www.example.com\/search&quot;&gt;&lt;input id=&quot;&quot; name=&quot;q&quot; type=&quot;search&quot; placeholder=&quot;Search&quot; \/&gt;\n&lt;button class=&quot;ht_search&quot; type=&quot;submit&quot;&gt;Search&lt;\/button&gt;\n&lt;\/form&gt;\n&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<p>This is the Form with an input filed to enter the search query, and a button to submit the query. ( button in not\u00a0necessary )<\/p>\n\n\n\n<p>two important thing have to notice here<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>action=&quot;https:\/\/www.example.com\/search&quot;<\/code><\/pre>\n\n\n\n<p>to where the form have to navigate ( For Dynamic Website Instead of hard-code this value, can use server side language to add dynamically, WordPress \/ PHP Version added later in this page )<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>name=&quot;q&quot;<\/code><\/pre>\n\n\n\n<p>&quot;q&quot; is Google Custom Search Engine default search parameter<\/p>\n\n\n\n<p>Now when user search for a term it will navigate to\u00a0<\/p>\n\n\n\n<p>https:\/\/www.example.com\/search?q=search-query<\/p>\n\n\n\n<p>Google Custom Search Engine will get the Search term form URL and show search result<\/p>\n\n\n\n<p>In the Search page where result have to show, Add Google Custom Search Engine code<\/p>\n\n\n\n<p>When using Custom Search box, you may not need the default search box. so select &quot;Result only&quot; or similar at &quot;Look and feel&quot; settings and click on &quot;save &amp; Get Code&quot;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"854\" height=\"773\" src=\"https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/look_and_feel_-_results_only.png\" alt=\"look and feel - result only - cse\" class=\"wp-image-1039\" srcset=\"https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/look_and_feel_-_results_only.png 854w, https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/look_and_feel_-_results_only-300x272.png 300w, https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/look_and_feel_-_results_only-768x695.png 768w\" sizes=\"(max-width: 854px) 100vw, 854px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"839\" height=\"488\" src=\"https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/result_only_-_code.png\" alt=\"\" class=\"wp-image-1047\" srcset=\"https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/result_only_-_code.png 839w, https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/result_only_-_code-300x174.png 300w, https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/result_only_-_code-768x447.png 768w\" sizes=\"(max-width: 839px) 100vw, 839px\" \/><\/figure>\n\n\n\n<p>The last line, it makes to add the search result only, now Google Custom Search Engine won&#x27;t Create Search box.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;gcse:searchresults-only&gt;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<p>If you are using WordPress, you can create the search form like above and add in a post or page.<\/p>\n\n\n\n<p>or can change the default search form &#8211; form searchform.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=&quot;ht_search_form&quot;&gt;\n&lt;form action=&quot;&lt;?php echo esc_url( home_url( &#x27;\/search&#x27; ) ); ?&gt;&quot;&gt;&lt;input id=&quot;&quot; name=&quot;q&quot; type=&quot;search&quot; placeholder=&quot;Search&quot; \/&gt;\n&lt;button class=&quot;ht_search&quot; type=&quot;submit&quot;&gt;Search&lt;\/button&gt;\n&lt;\/form&gt;\n&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Styles \/ CSS<\/h2>\n\n\n\n<p>This may not be perfect as you wish, but will give some idea<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.ht_search_form button {\n\tcolor: #000;\n\tbackground-color: orange;\n}\n\n.ht_search_form input {\n\tmax-width: 200px;\n}<\/code><\/pre>\n\n\n\n<p><strong>.ht_search_form button<\/strong>\u00a0 \u00a0&#8211;\u00a0 selects the button\u00a0<\/p>\n\n\n\n<p><strong>color: #000;<\/strong>\u00a0 \u00a0&#8211; change the button text color<\/p>\n\n\n\n<p><strong>background-color: orange;<\/strong>\u00a0 &#8211; change the button background color<\/p>\n\n\n\n<p><strong>.ht_search_form input<\/strong>\u00a0 &#8211; selects the input field<\/p>\n\n\n\n<p><strong>max-width: 200px;<\/strong>\u00a0 &#8211;\u00a0 make the width of the input field does not exclude 200px<\/p>\n\n\n\n<p>This syntax are added for an idea. based on this can edit the values easily. ( button text color, background color, input filed max width )<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"266\" height=\"224\" src=\"https:\/\/holithemes.com\/blog\/wp-content\/uploads\/2018\/03\/simple_form.png\" alt=\"simple search form\" class=\"wp-image-1168\" \/>\n    <figcaption>o\/p\u00a0 \u00a0( image )<\/figcaption>\n<\/figure>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<p><a href=\"https:\/\/holithemes.com\/blog\/add-custom-search-engine-in-your-website-using-google-custom-search-engine-cse\/\">Add Google Custom Search Engine on you Website<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Create Simple Search Form For Google Custom Search Engine.\u00a0 A simple search form, less wait. and no need to load any dependencies to display a search form This is the Form with an input filed to enter the search query, and a button to submit the query. ( button in not\u00a0necessary ) two important thing [&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-974","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\/974","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=974"}],"version-history":[{"count":0,"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/posts\/974\/revisions"}],"wp:attachment":[{"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/media?parent=974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/categories?post=974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/holithemes.com\/blog\/wp-json\/wp\/v2\/tags?post=974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}