Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
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 lovers 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 »
  • Raghu

    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?

  • Rajnish

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

  • Chris

    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?

    • WPBeginner Support

      Chris, try regenerating code by creating a new custom search engine.

  • Deepak Singh

    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

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

  • Joy Baker

    Oops. Guess the form requires pre tags or something.

  • Joy Baker

    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.

    • WPBeginner Support

      yes replace the entire code with just the code for your Google CSE.

  • David Trees

    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

      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.

  • Abhisek

    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 :

  • George Byers

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

    • WPBeginner Support

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

  • John

    Thanks so much! You always have the best tutorials.


  • Huzaima Khan

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

  • amrilio

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

    • WPBeginner Support

      We use a customized version of Floating Social Bar plugin.