Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Add Google Search in a WordPress Site (The Easy Way)

Ever wondered why visitors spend just seconds on your WordPress site before hitting the back button?

One overlooked reason is poor search functionality. If users can’t quickly find what they’re looking for, they’ll leave, often without engaging or converting.

By default, WordPress’s built-in search is pretty limited. It doesn’t recognize typos, synonyms, or context, which makes it harder for people to discover your best content.

That’s where Google Search comes in.

Google’s powerful search engine delivers fast, relevant results; the kind your visitors are used to. It’s smart enough to understand intent, fix spelling mistakes, and surface content that WordPress search might miss entirely.

After testing several methods, we’ve found a quick and reliable way to set it up. In this guide, we’ll show you how to add Google Search to your WordPress site – no complicated setup. 🧑‍💻

Add Google Search in a WordPress Site

Why Should You Use Google Search in WordPress?

The default WordPress search feature is not very useful and often fails to find relevant results to user queries. This forces many site owners to look for alternatives.

You can use a popular WordPress search plugin. However, the problem is that you still have to manage that plugin, and it 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 WordPress site.

Plus, the Google search is fast, users already trust the brand, and you will not have to maintain or update it. You can even allow users to search external websites on Google if needed.

Having said that, we’ll show you how to easily add a Google site search to your WordPress site. Here are all the things we’ll share in this guide:

Let’s get started.

How to Add Google Search to a WordPress Site

You can easily add Google Search to your WordPress site by visiting the Google Programmable Search Engine website.

From here, click the ‘Get Started’ button.

Click the get started button on the Programmable Search Engine page

This will direct you to the ‘Create a new search engine’ page, where you must add a name for the search form you are about to create.

Next, select the ‘Search specific sites or pages’ option in the ‘What to search?’ section and add your WordPress site’s URL.

Now, the Google Site Search will only index the content available on your website. However, if you want Google to show search results from other websites as well, then you can choose the ‘Search the entire web’ option.

Add website URL to create Google Site search

Next, scroll down and toggle on the ‘Image Search’ option to allow your Google Search form to index images on your website. We recommend this option if you sell photos online, have a photography website, or run a travel blog.

After that, you can also toggle on the ‘Safe Search’ switch so that users won’t be shown inappropriate results for their queries.

Once you are done, click the ‘Create’ button.

Click create to generate a google search engine ID

Google will now generate your search engine ID code for you.

From here, simply copy the code and paste it into a Notepad app or plain text editor.

Copy the Google Search Engine ID from the website

Now, you must visit your WordPress dashboard and edit your theme files to add the search to your site’s <body>. However, this can be risky, and the smallest error can break your website.

That is why we recommend using WPCode instead. It is the best WordPress code snippets plugin on the market that makes it safe and easy to add custom code.

Some of our partner brands use WPCode to add and manage custom code snippets on their websites. It’s been working exceptionally well for them, and you can find more about it in our detailed WPCode review.

WPCode's homepage

💡 Note: WPCode has a free plan that you can use for this tutorial. However, upgrading to the pro version will give you access to more features like smart conditional logic, a cloud library of code snippets, and more.

First, you need to install and activate the WPCode plugin. For detailed instructions, see our beginner’s guide on how to install a WordPress plugin.

Upon activation, visit the Code Snippets » + Add Snippet page from the WordPress admin sidebar. Here, click the ‘+ Add Custom Snippet’ button under the ‘Add Your Custom Code (New Snippet)’ option.

WPCode add custom code snippet

This will take you to the ‘Create Custom Snippet’ page, where you can type any name you like for the snippet. Then, select ‘Universal Snippet’ as the code type from the dropdown menu on the right.

Once you do that, simply paste the Google Search Engine ID into the ‘Code Preview’ box.

Paste the Google Search Engine ID into WPCode preview box

Then, scroll down to the ‘Insertion’ section and select the ‘Auto Insert’ mode. Upon activation, the Google Search form will be automatically added to your site.

After that, you can expand the ‘Location’ dropdown menu to choose where you want to display your search box.

For example, if you want to display the search form at the top of all your posts and pages, then you can select the ‘Insert Before Post’ option.

Choose location and insertion for the search engine ID

Next, scroll back to the top and toggle the ‘Inactive’ switch to ‘Active’.

Finally, click the ‘Save Snippet’ button to store your settings.

Save Google Search Engine ID snippet

You have successfully added a Google Site search form manually.

You can now visit your WordPress blog to see it in action.

Google Search preview

Alternative: Use SearchWP to Create an Amazing Search Form

If you find it difficult to add Google Site Search to your website or you are looking for an alternative, then you can use SearchWP, the best WordPress search plugin on the market.

Here’s how it works: This plugin automatically replaces the default search form and allows users to find anything they need across your site. We’ve extensively tested this plugin, and you can explore its features in our detailed SearchWP review.

The SearchWP search plugin for WordPress

SearchWP lets you create a custom relevance scale to adjust the search algorithm.

You can also make any part of your site searchable, including PDFs, custom post types, media, blog archives page, blog comments, WooCommerce products, and more.

Creating a WordPress search form for custom post types

If you have a multilingual site, then you can also create a multilingual search with the plugin.

However, you must keep in mind that, unlike Google Search, the plugin can only index and show results for content available on your website. For more details, you can see our tutorial on how to improve WordPress search with SearchWP.

FAQs: How to Add Google Search to a WordPress Site

If you’re still unsure whether Google Search is the right fit for your WordPress site, don’t worry. Here are some of the most common questions we hear from users:

How much does it cost to add Google Search to a WordPress site?

Adding Google Search to your WordPress site is completely free. That said, if you want extra customization or advanced features, there might be some costs depending on the tools you choose to use.

Do I need coding skills to add Google Search?

Not really. You can just follow the steps in this guide, as we’ve provided a working code snippet you can copy and paste into WPCode. It’s a simple, beginner-friendly way to add Google Search without editing your theme files.

Can I customize the appearance of Google Search on my site?

Yes, you can style it to match your site’s branding. Google’s Programmable Search Engine gives you options to adjust how the results look and feel.

What if I want to remove Google Search later?

It’s easy! You can turn the code snippet off or remove it using your plugin settings anytime you want.

Video Tutorial: How to Add Google Search to a WordPress Site

Not a fan of reading instructions? No problem! We’ve created a handy video tutorial that walks you through the process:

Subscribe to WPBeginner

We hope this article helped you learn how to easily add Google Search to a WordPress site. Next, you may also want to see our beginner’s guides on:

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

83 CommentsLeave a Reply

  1. When I insert the google engine id the plugin automatically creates a page where the search result will be displayed. But what I need is to change the link of the page where the search result will be displayed. How can I do that?

  2. I am using the WP Google Search Plugin. I was so frustrated because I couldn’t get the search icon show. Your tip on customizing the search box through the dashboard in Google Custom Search solved the problem.

  3. Cool artricle but what I wanted to have a the custom search box in the centre of a blank page as if it was a google search page. I found the plugin Blank Slate which gives the blank page just not sure how to either center and limit the width of the search box either by code or shortcode any ideas ??

  4. Thanks wpbeginner your articles have always helped me a lot. I wanted to do it manually because that way wherever I have search form it’ll be replace by custom google search and your article did work for me as always :)

    When i tried it first it didn’t work because I registered website as http(s) or didn’t enclose the code within a div so it really gave e a hard time. Anyway i am all thanks for your help!!

    Thanks again :)

  5. It works exactly how I want it to, searching 2 different web sites, as long as I am logged into WP Admin. Once I’m no longer logged in to the WP Admin I get

    Not Found
    Apologies, but the page you requested could not be found. Perhaps searching will help.

    What step did I miss?

    • I don’t have much idea about web designing and further customizing. I am learning wordpress blogging from last 5 months, and I think it may be due to a problem while publishing your search result page. There is a visibility option in edit page mode. If that page is private or password protected, this problem you said may arise. If it is done so, make it public..

  6. Plugin method works well for me. But I am trying to replace theme’s native menu bar search functionality with CSE. Its wordpress native search only. So manual editing searchform.php method should work for me.
    But after editing searchform.php my search widget vanishes from sidebar. I am using Colormag theme by themegrill.
    Looking out for a help.

    I am also keen to see mentioned in above comment but this site is offline now. I tried to fetch it from wayback machine but couldn’t found in its past impressions.

    • The same thing happens to me when I paste that code into searchform.php. Not sure this is proper as searchform.php by default is an HTML form. The code copied from Custom Google Search is a JavaScript tag…. should this even work??

  7. Really Helpful topic as always.

    I am using a Plugin in my Site. How can I exclude ads from Search Results

  8. Hi Wpbeginner,

    This worked like charm! The manual method is just as awesome as you wrote. Google custom search now showing on my site!

    Thank you so much.

  9. Can you only implement custom search when the site is live and indexed by Google? If it’s hidden or password protected, can it be added then?

  10. I am trying to add Google Search with the Plugin to my website. I got as far as the step where I am supposed to paste the search engine ID into the WP Google Search’s settings page. My settings page does not seem to have any place where I can do this. Can you tell me where the ID should be pasted and what it is called?

    Thanks.

  11. the manual way of doing this is poorly described and a total waste of time. If you gonna do something do it right ir dont do it at all.

    • If you are having difficulty using the manual method, then please try the first method. It is easier to add Google Search with the help of a plugin. If you need to do it manually, then please let us know which part isn’t clear and we will try to explain it here.

      Admin

      • Manually Adding Google Search doesn’t work (I’m using colormag theme), U need to Update the article

  12. By using this search plug-in will I be able to see a report on what words were typed in the box to search for?

    I want to know what people are searching for, so I can create content based on their search.

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

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

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

  16. Hi!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Admin

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

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

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.