Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Add Google Search in a WordPress Site

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Add Google Search in a WordPress Site

Do you want to use Google search on your WordPress site? Although WordPress comes with a built-in search feature, it is not very good. That’s why many site owners add Google site search on their WordPress site. In this article, we will show you how to easily add Google Search in a WordPress site.

How to Add Google Search in WordPress

Why You Should Use Google Search in WordPress?

The default WordPress search feature is not very useful. It often fails to find the relevant results. This forces site owners to look for alternatives.

There are plenty of search plugins for WordPress like SearchWP, Swiftype, etc. The problem is that you still have to manage them, and they will have an impact on your server resources.

On the other hand, you can use Google’s reliable and powerful search feature instead. It is free, allows you to limit the search to your sites only, and can be run from your own site.

Other benefits of using Google search are speed, users already trust Google brand, and you will not have to maintain or update it.

Having said that, let’s see how you can easily add Google site search to your WordPress site.

Method 1: Adding Google Search in WordPress with Plugin

This first method is easier and recommended for beginners. It allows you to add Google search to your WordPress site without modifying your theme files.

First thing you need to do is install and activate the WP Google Search plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Settings » WP Google Search to setup the plugin.

Settings page for WP Google Search

The plugin will ask you to provide a Google Search Engine id. Here is how you will get a search engine ID.

Visit Google Custom Search website and click on New Search Engine link on the left.

Creating new Google Custom Search engine for your WordPress site

Simply provide your WordPress site’s URL in ‘Sites to Search’ field. Next, you need to choose the language of your website. Lastly, click on the create button to continue.

Google will now create your custom search engine and will show you a success message with links to further actions. You need to click on the control panel button to continue editing your search engine.

go to Google custom search engine's control panel

This will take you to the control panel for your custom search engine. First, you need to click on the ‘Search engine ID’ button and copy your search engine ID.

Copy your Google custom search engine ID

Next, you need to click on the ‘Look and Feel’ section. Under the layout tab, select results only.

Choose layout for search results page

Once you are done, click on the save button at the bottom of the page to store your changes.

Now you can switch back to your WordPress site. Paste the search engine ID you copied earlier in the WP Google Search’s settings page and then click on the save changes button to store plugin settings.

After that you need to visit Appearance » Widgets page. There you will notice WP Google Search widget in the list of available widgets. Drag and drop the widget to a sidebar where you want to display the search form.

Google custom search engine widget

Click on the save button to store your widget settings.

You can now visit your website to see the search form in action.

Google custom search form in WordPress

Method 2: Manually Adding Google Search in WordPress

This method requires making changes to your WordPress theme or child theme files. It is not recommended for beginners. Make sure to backup your WordPress site before making any changes to your theme files.

Visit Google Custom Search website and click on New Search Engine link on the left.

Creating new Google Custom Search engine for your WordPress site

Simply provide your WordPress site’s URL in ‘Sites to Search’ field. Next, you need to choose the language of your website. Lastly, click on the create button to continue.

Google will now create your custom search engine and will show you a success message with links to further actions. You need to click on the Get Code button to continue.

Get code for your Google custom search engine

On the next screen, you will see some code in a textarea. You need to copy this code.

For this next step, you will need an FTP client. If you need help, then see our guide on how to use FTP to upload WordPress files.

Connect to your website using FTP and then go to /wp-content/themes/your-current-theme/ folder. Replace your current theme folder with the name of your current theme.

Editing searchform file

Locate the searchform.php file in your WordPress theme directory. Download this file to your computer and open it in a plain text editor like Notepad.

Delete all contents of the file and paste your Google custom search engine code. Save the file and then upload it to back to your WordPress site using FTP.

After pasting Google custom search code, go to Appearance ยป Widgets to drag and drop the Search widget into your sidebar.

Adding search widget

Click on the save button to store your widget settings.

You can now visit your website to see the Google search in action on your WordPress site.

Customizing Google Custom Search Engine Colors and Looks

Go to Google Custom Search website and edit your search engine. This will show settings for your custom search engine. Click on Look and Feel from sidebar.

Google custom search has some pre-made themes available to choose from. You can also click on customize tab and choose your own font, border, and background colors.

Customize colors and appearance of Google custom search

Once you are done customizing the look of your search box, simply save your changes. You don’t need to paste the code again, these changes will be automatically applied to your search form.

We hope this article helped you learn how to add Google search in a WordPress site. You may also want to see our list of 19+ free Google tools every WordPress blogger should use.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.


Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

Comments

  1. Ameer Shaik says:

    I have updated through plugin method. Only search button is not displayed properly. Please suggest(The text “Search” is moved down, only top portion is visible). Pl suggest

  2. Bruno Bezerra says:

    Beautiful tool! Having a search field is more than necessary.

  3. Jennifer says:

    Another awesome tutorial – I didn’t even know it was possible to use Google Search like this! I’ve now got this running on my website, thanks so much!

  4. Imran Khan says:

    Nice post, very helpful as well as easily understandable. I have also created my custom search bar by following your steps. Thanks for sharing this great post with us.

  5. Angelo says:

    Hi!

    Do we have to choose among among the 5 font options available or we can import a font we like better?

  6. wiziwiz says:

    how to set it so the results when clicked open in the content area?

  7. Eric Kazda says:

    Can somebody tell me why this is a more beneficial search than using the standard WordPress search form? Are there SEO implications? I’m just not sure why anyone would use this over the standard search.

    • Adam Connell says:

      I generally find that whenever I search a website for a topic, and it’s using WordPress default search – I’ll get VERY poor results.

      They’ll lack relevance.

      By using Google’s custom search, you won’t get any SEO benefits but your readers will find it easier to get what they’re looking for.

  8. Priti says:

    In “Search by Google” how to we specify the our google search id ? In widget don’t we have to keep the google search engine id?

  9. Carol Long says:

    Hi – can you tel me please how to remove this? I have just seen it appear on all my pages and I don’t want it at all!

    Many thanks

  10. Richard Bishop says:

    Hello, and thank you for creating this post and video. I really found it to be helpful in terms of providing better search results for my site WarCraft Press.

    I would however say that you should have pointed out at the beginning of the lesson there are 2 ways to accomplish this task. I did it once with out the plugin then later realized there was a plugin for it.

    That said thanks again for a great lesson and I certainly look forward to future lessons!

    Kombear
    WarCraft Press

  11. cowboy Mike says:

    Howdy,
    I have seen you recommend editing wp files and wp theme template files like you have in this article for the searchform.php file.

    My concern is when there is a theme update or wordpress update wouldnt the changes to the searchform.php suggested here be lost after for example a theme update?

    Happy trails, Mike

  12. Shahadat Hossain says:

    can i use google custom search box and wp normal box all together in my site. or i will have to use only one search box between two of this search box

  13. Nasser says:

    How to make a search bar that join to google? Not just a small windows as Custom google search. Exactly work as google search.
    Thanks.

  14. Caroline says:

    The search results opens up in a new window, how can I open them in my search.php?

  15. Ramesh Tatipigari says:

    Hi ,

    I want to add google search bar to every post of my wordpress site or i want to add google search bar to below main menu could you please help me regarding this.

  16. boooka says:

    my search terms cannot be seen. what happened

  17. Day Milovich says:

    i prefer to change wordpress search completely with google custom search engine to get better traffic from google.

  18. Rahul Yadav says:

    Hi, I would like to know how to use google custom search in menus like you use……..

  19. Vipul Behl says:

    Thanks for the tutorial i was able to create a search for my blog.

  20. Javed Ahmadzai says:

    Well, I have done the same procedure. my theme does not contain searchform.php i created it but it contain searchresults.php i think its theme’s search. but after creating the searchform.php and pasting the code there. another search widget not appeared. Only sahifa search which is theme’s so please can you tell me what the problem. :(

  21. tony greene says:

    This doesn’t work for Genesis sites with child themes.

  22. Raghu says:

    Hi, I would like to know if I can use google custom search for my intranet portal. I have setup wikipedia for internal purpose and I would like to integrate google custom search for this, however I am not getting result when I integrate.
    So the question is: Is google custom search meant only for public websites?

  23. Rajnish says:

    Really helpful post. I integrated search box for my Website successfully. Thanks WPBeginner :)

  24. Chris says:

    Hi, I went through these steps exactly for my WordPress site, but the search box doesn’t appear anywhere. There are no .js errors in the console. I put a border around the containing div and the border appears, but there’s nothing inside it. I pasted the code I generated from Google inside searchform.php. As a test I also tried pasting the google code on a test page, but still no luck.

    Any ideas on troubleshooting?

  25. Deepak Singh says:

    Can you please guide me how we cana dd Custom Search in genesis child theme. I tried many tutorials but none of them work.

    • WPBeginner Support says:

      Genesis is a theme framework, you should check out their documentation or use support forums.

  26. Joy Baker says:

    Oops. Guess the form requires pre tags or something.

  27. Joy Baker says:

    Forgive my newbie status, but when pasting the code into the search.php of my theme’s search page, do I replace the code in the page with Google’s code? I am an idiot when it comes to php code. I know what it looks like, what the opening/closing tags look like, but I have no idea what you mean when you say paste the code in the page.

    Where? Replace it all or between the opening/closing tags or… ???

    Current code looks like this:


    So, do I replace the entire code in the page with the custom Google Search I’ve created?
    Google code:


    Thanks for any help you can give.

  28. David Trees says:

    Thanks for a very well written article. It is easy to read and follow,even for a complete newbie.

    The only thing I don’t get, is how to do this;

    “If your theme does not have a searchform.php file, then you need to create one using a text editor like Notepad and upload it to your theme directory using FTP client”

    Remembering I am a newby. I did instal my WP site to my shared hosting by following clear instructions, using FTP. So I guess I am saying how does one create the searchform.php file?

    Thanks again.

    • WPBeginner Support says:

      Open your FTP client and connect to your shared hosting site. Navigate to /wp-content/themes/ directory. Click on the theme you are using. For example if you are using twentytwelve theme you will see a directory twentytwelve there, open it. Once you have opened your theme directory in your FTP client, right click and select ‘Create new file’. A new dialog box will appear enter searchform.php as the file name. That’s all you have created searchform.php file.

      You can also create this file on your computer by opening a plain text editor like notepad and save file as searchform.php, after creating the file you can upload it to your theme directory using an FTP client.

      You can edit this file from inside your WordPress Admin area. Go to Appearance » Editor and click on searchform.php file from the list of files on the right.

      • Patricia says:

        I tried to do just that but something else happened. The search box disappeared and was replaced by an ad. The widgets below the search widget area in my primary sidebar also disappeared. I’ll figure this out soon. It’s a pretty nifty feature.

  29. Abhisek says:

    This is a very simple and easy to digest. But, if anyone want to use his/her theme’s default search bar and display the search results then how will he integrate google cse with his theme’s search, I found a great and simple method, it just requires editing your search.php file of your theme, just replace the php statement that is responsible for showing the search results. Feel free to read the full post at my blog : http://technikaly.com/wp/google-custom-search-engine-integration-tutorial/144/

  30. George Byers says:

    Thats great and all… but my search field is on the menu bar.

    • WPBeginner Support says:

      Look in the code if it is using the function <?php get_search_form(); ?> then this method should work for you.

  31. John says:

    Thanks so much! You always have the best tutorials.

    John

  32. Huzaima Khan says:

    Really helpful post. I integrated search box for my blog successfully. Thanks WPBeginner :)

  33. amrilio says:

    Can you tell me, how to make share & comment button like your blog? please

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.