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
Follow WPBeginner on YouTube
How to Add Google Search in a WordPress Site

As you may have discovered, in spite of its phenomenal performance as a blogging platform/CMS, WordPress falls woefully short in the search department. There are other plugins available that will improve your search results, like Amazon CloudSearch in WordPress with Lift or SearchWP. But for those of you who don’t want to install 15 of them to just barely imitate the functionality of modern search engines, there is another option: replace WordPress search with Google custom search. In this tutorial, we will to show you how to add Google Custom Search in WordPress.

Adding Google Custom Search in WordPress

Video Tutorial

If you don’t like the video or need more instructions, then continue reading.

Create a Google Custom Search Engine for your WordPress Site

Go to Google Custom Search Engine and sign in using a Google account. Once there, click on New Search Engine and provide your WordPress website’s URL. The URL will also be used as your search engine’s name in your Google Custom Search Engine dashboard. Click on Create button to proceed to the next step.

Creating a Google Custom Search Engine for your WordPress website

On the next page, you will see a notification that you have successfully created your custom search engine. You will be presented with an option to add it to your site or get the public URL. To add this custom search engine in your WordPress site click on the Get Code button.

Get code to add Google custom search engine to your website

On the next page you will get the code for your custom search engine. Copy the code you will need it in the next step.

Adding Google Custom Search in WordPress

Go to Appearance » Editor in your WordPress admin area and click on searchform.php file to open it in the editor. Paste the custom search engine code in the file. It is alright if this file does not contain anything else and just the Google custom search engine code.

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.

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

Adding search widget in WordPress sidebar

That’s all, preview your site to see it in action.

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 premade themes available to choose from. You can also click on customize tab and choose your own font, border, background colors. Once you are done customizing the looks of search box, simply save and your changes will appear on your site.

Customize look and feel of Google custom search engine

We hope this article helped you add Google Custom Search to your WordPress site. For questions and feedback please leave us a comment below or join us on Facebook and Twitter.


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. 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

  2. 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

  3. 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

  4. 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.

  5. Caroline says:

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

  6. 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.

  7. boooka says:

    my search terms cannot be seen. what happened

  8. Day Milovich says:

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

  9. Rahul Yadav says:

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

  10. Vipul Behl says:

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

  11. 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. :(

  12. tony greene says:

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

  13. 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?

  14. Rajnish says:

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

  15. 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?

  16. 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.

  17. Joy Baker says:

    Oops. Guess the form requires pre tags or something.

  18. 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.

  19. 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.

  20. 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/

  21. 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.

  22. John says:

    Thanks so much! You always have the best tutorials.

    John

  23. Huzaima Khan says:

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

  24. 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.