How to Add Google Search Engine to WordPress Blog – Widget – Simple HTML code?


In this post and this post, we know to replace the inbuilt wordpress search engine by using Google. It requires modification of PHP templates, which may not be possible in some cases. You could do it using the following simple way.

You just need to add a Text-widget following [Appearance] – [Widgets]. Then add the following HTML code.

<form onsubmit='javascript: document.getElementById("q").value+=" site:"+window.location.hostname;' action='https://www.google.com/search' method='GET'>
<input name='q' id='q'/><input type='submit' value='Search'/>
</form>

The idea is simple and the code is straightforward. It uses a HTML form that will submit to the Google Search by GET method with the query string q=query. And a ‘site:’ + window.location.hostname will be added to the query so the search is limited to your domain only (Google search query syntax).

widget-search-engine How to Add Google Search Engine to Wordpress Blog - Widget - Simple HTML code? google api HTML5 wordpress

widget-search-engine

And you are allowed to have two search engines – Google and the inbuilt WordPress search.

search-via-google-vs-wordpress-search How to Add Google Search Engine to Wordpress Blog - Widget - Simple HTML code? google api HTML5 wordpress

search-via-google-vs-wordpress-search

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
286 words
Last Post: How to Show Related Articles using the Matched Content from Google Adsense?
Next Post: Quickhost UK - 1 Gigz Network Speed Upgrade for VPS

The Permanent URL is: How to Add Google Search Engine to WordPress Blog – Widget – Simple HTML code?

Leave a Reply