Image of hands typing on keyboard with search bar overlay

How to Add Google Search in a WordPress Site

WordPress comes with a built-in search feature that’s easy to implement and simple to use. However, when you compare it to popular search engines such as Google, WordPress’ default offering may leave a lot to be desired.

Fortunately, it’s easy to harness the power of Google by adding a search bar to your website. This powerful and familiar feature will help users find exactly the content they need, improving their experience and increasing key metrics such as session duration

In this article, we’ll cover two ways to add Google search to your WordPress website. We’ll show you how to add this option to any page or post, and even how to code Google search into your website’s theme. Let’s get started!

What Benefits Does Adding Google Site Search to Your WordPress Site Offer?

Google is a household name. By featuring a Google search bar on your website, you can help legitimize your business in your customers’ eyes, and offer them a better experience.

The Google search bar is instantly recognizable to many people. It’s estimated that 40–60 billion searches happen on Google in the US alone, every single month. The majority of your visitors will likely have previous experience with Google’s search bar. This provides a more seamless user experience for them, since they’ll immediately know how to interact with your website’s search.

Google’s search bar is reliable and powerful, and has a range of customization options. This includes the ability to limit searches to your website. That can encourage visitors to spend more time on your site, rather than pointing them in the direction of third-party content.

This feature is also free to use, and easy to implement. In this article, we’ll be sharing two separate ways you can add this search bar to your WordPress website. 

How to Add Google Site Search to WordPress With a Plugin

You can add a Google search bar to any page or post using the WP Google Search plugin. This tool lets your visitors search the entire web, or you can narrow the search to a list of approved sites.

You can then add the Google search box to your site using either a shortcode or a custom widget. Let’s walk through how that process works, in just four steps.

Step 1: Download a Google Search Plugin

Once you’ve installed and activated WP Google Search, the next step is registering with the Google Custom Search Engine. You can then generate a Google Search Engine ID, which is how you’ll communicate with the Google Search service. 

To generate this ID, head to the Programmable Search Engine and select Get Started. In Sites to Search, enter your website’s URL:

Screenshot of programmable search engine where you can then generate a Google Search Engine ID

You can then give your search engine a name. Click on Save, and Google will generate your Custom Search Engine. 

Step 2: Manage Your Google Search Settings

In the left-hand menu, select Edit search engine > Setup. Make sure the Basics tab is selected:

Edit search engine setup Google

There you can configure your search settings. This includes enabling or disabling Google Image Search and SafeSearch:

enable or disable Google Image Search and SafeSearch

You can also restrict search results based on region. To do this, make your selection in the Region drop-down menu. You can then select the Restrict search results to region slider: 

Restrict search results to region

Finally, you can choose whether to restrict your search to specific websites, or even limit searches to your site only. This can be useful if you want to encourage visitors to explore your content, rather than pushing them towards external resources:

Restrict search to your site

Next, copy your search engine ID and switch back to your WordPress dashboard. You can then navigate to Settings > WP Google Search, and paste that number into the Google Search Engine ID field. 

Step 3: Add the Search Bar to Your Site Using a Widget

You can now add the new search bar to your website, using the WP Google Search widget. Navigate to Appearance > Widgets, find the WP Google Search widget, and drag it to the sidebar where you want to display your search feature:

Add the Google search bar to your site

You can add a title to your widget, or hide the title completely. Click on Save when you’re ready, and the search bar will appear on your website. Visitors can now interact with Google by typing into the search box. By default, the results will appear as an overlay across your website. 

Step 4 (Optional): Display the Search Bar Using a Shortcode 

What if, instead of adding the search feature to your entire site, you want to display it on specific pages or posts only? To make that happen, you’ll need to use a shortcode instead of a widget.

To get started, open up the relevant page or post for editing. You can then copy and paste the [wp_google_searchbox] shortcode into the exact location where you want to display the search bar: 

Display search bar search code WordPress

You can then either publish or update the page or post. Your search bar will appear wherever you placed the shortcode.

You can also insert the shortcode into your website’s theme. This can be a quick and easy way to feature a Google search bar across your website. However, editing theme files can cause issues with your website if you’re not careful. Before making any changes at the code level, it’s always a good idea to create a backup

To insert a shortcode into your theme, navigate to Appearance > Theme Editor. Open the Select theme to edit drop-down menu, and choose your current theme:

Appearance > Theme editor WordPress

Towards the right-hand side of the screen, select the file that you want to edit. Most of these files are self-explanatory: for example, header.php controls your website’s header. Copy and paste the following into your chosen file, in the location where you want your search bar to appear:

<?php echo do_shortcode("[wp_google_searchbox] "); ?>

Select Update File. The search bar will then be inserted into your WordPress theme, and should appear across your website.

How to Add Google Site Search to WordPress Without a Plugin

You can also add a Google search bar to your website without installing a plugin. In this section, we’ll show you how to replace the default WordPress search bar with Google Custom Search. 

Step 1: Visit the Google Custom Search Website

To begin, head over to Google Custom Search. In the left-hand menu, select New Search Engine.

This is where you’ll build your customizable search box. You’ll also generate the code you need to add Google Site Search to your website without a plugin. 

Step 2: Provide Your Site’s URL

In Sites to Search, enter your website’s URL. You can then choose your website’s language and click on Create. Google will now build your custom search engine:

Google programmable search

On the subsequent screen, select Get code. This generates the code you’ll need, in order to replace WordPress’ default search with Google search. 

Step 3: Get Your Custom Code

You can now copy the provided code, and add it to your website’s template. Remember to create a backup first, just in case anything goes wrong.

After creating your backup, navigate to Appearance > Theme Editor, and open your theme for editing. Along the right-hand side of the screen, select searchform.php. In the file editor, delete the entire contents of searchform.php, and replace it with the code you copied in the previous step:

Create a backup of WordPress site

Save your changes by clicking on Update File. Now, whenever users interact with any search bar on your website, it will connect them to Google search. 

Customize Your Site With WP Engine

A Google search bar can improve the user experience by making it easy for visitors to find interesting and engaging content. However, if you’re really going to wow your audience, then you’ll need a WordPress hosting provider that guarantees a high level of security, performance, and reliability.

At WP Engine, we excel in all of those areas. Check out our plans, and get ready to take your user experience to the next level!

Get started

Build faster, protect your brand, and grow your business with a WordPress platform built to power remarkable online experiences.