The default WordPress search may be fine when you are just starting out, but as your site grows you will start to see some limitations. Notably, as the amount of content on your site increases, you will realize that it doesn’t always show the most relevant results – making your content harder to find for your visitors.

Google is most famous for search, and using Google Search on your site can provide a much better experience for your users. If they can find what they’re looking for, it becomes much easier to keep them on your site.

This article will look at why you should consider switching from the default WordPress search to using Google Search on your site, then step you through how to make the switch.

Why You Should Switch to Using Google Search for WordPress on Your Site

Though improvements have been made to the default WordPress search in recent years, it still works by querying the WordPress database, looking for keyword matches in posts and pages. The basic search has some limitations that affects usability:

  • Results are often chronological (although some attempt has been made to weigh relevance).
  • Comments, custom post types, and other data are not included without the use of a specialized plugin, such as SearchWP.
  • The search results cannot be refined through advanced parameters.
  • The search results display the default WordPress excerpts (often the first paragraph).

Many of the limitations can be addressed with plugins, and in a previous post we looked at the best search plugins available.

Google, on the other hand, is the standard in internet search. We use the word as a verb (“just google it!”) to show how they have captured the concept of search. So if you or your users have started to become frustrated by the results of the WordPress search on your site, you can take advantage of Google’s search expertise.

Replacing the default WordPress search with Google search can help by:

  • Including more relevant search results through the power of Google’s indexing and ranking.
  • Including all content on your website within search results.
  • Searching across multiple domains to provide results from your other web properties.

As the website owner, Google search also enables you to monetize your search results by integrating AdSense, and driving traffic to your other web properties included in the search.

Even the WordPress.org website uses Google search, so it can definitely handle your website.

Let’s see how easy it is to get started!

How to Set Up Your Google Custom Search Engine

Google-Custom-Search-Engine

Google knows they have great search, so they provide Google Custom Search to make it easy for websites to add a search box to their site that uses Google’s technology. The basic tool is free, but if you want to go further into customizing the design (like removing ads or the Google branding), or to add more powerful features (like rich snippets and data biasing), you can look at Google Site Search (which starts at $100 per year).

Creating a Custom Search Engine for your website is very simple:

  1. Log into Google Custom Search Engine.
  2. Click New Search Engine and enter the details:
    • Sites to searchYou can enter one or more URLs for the sites or pages you want to search, on your site or any other.
    • Language: This is the language of the search engine itself, so it affects buttons and design elements.
    • Name: This is auto-generated from the URLs entered above, but you can change it.
    • Advanced options: You can additionally restrict the search to only pages that include certain Schema.org types, such as Product or Event.
  3. Click Create.

Your Custom Search Engine is now ready! The next page will enable you to add it to your website, view it online, or modify it through the control panel. You can add the Custom Search Engine (CSE) to your website in two ways:

  1. Add Google CSE code to your website manually.
  2. Use Google CSE ID with a plugin.

We’ll cover both of those options below, before looking at ways you can customize the search engine.

How to Add Your Google Custom Search Engine to Your WordPress Website Manually

You can add the Google CSE to your website manually. This is the fastest way, and may be preferred for those of you who don’t want to add yet another plugin to your site. If all you want to do is completely replace the default WordPress search form with the Google CSE, the manual approach gets that done with no fuss.

When you successfully create your CSE, you are given an option to add it to your site:

Custom-Search-Engine

Click the Get Code button, and copy the code in the box on the following page:

Google-CSE-Code

Once you’ve done that, go to Appearance > Editor in the WordPress admin, then click on searchform.php in the list on the right to open it in the editor:

Edit-Search-Form

Once that’s done, paste the Google CSE code into this file. You can replace the contents of the file completely, and once you’re done, click Update File.

This is pretty straightforward, but there are a few things to look out for:

  • In general, you should really create a child theme for your theme rather than editing the code of the included files. We’ve covered why you should use a child theme and how to create one before.
  • If your theme doesn’t have a searchform.php file, you can create one using a text editor and upload it to your theme directory.
  • If you want to include the search form somewhere new in your sidebar, you can go to Appearance > Widgets to drag the search widget into a sidebar:

Add-Search-Widget

If you’re not comfortable adding the code yourself, you can choose to use a plugin instead. Let’s see how that works!

How to Add Your Google Custom Search Engine With a Plugin

There are a couple of plugins you can use to add Google’s CSE to your site:

1. WP Google Search (Free)

WP-Google-Search-plugin

If you are on a budget and want a free plugin to help you add Google CSE to your site, you can’t go wrong with WP Google Search. This plugin has over 6,000 active installs and a 4.5 star satisfaction rating.

To use this plugin, copy your Google CSE ID by going to the Setup page in the CSE dashboard:

Google-CSE-ID

Paste that ID into the plugin’s settings and you’re ready to go!

The plugin has limited settings, but you can customize the search within the CSE dashboard, as we’ll discuss shortly.

2. Custom Google Search ($49 per Month, as Part of a WPMU DEV Subscription)

Custom-Google-Search-plugin

A paid option for working with the Google CSE is WPMU DEV’s Custom Google Search. As with their other plugins, it is available as part of their monthly membership ($49 per month) which includes all their plugins and themes.

This plugin requires you to copy the Google CSE code (not the ID) into its settings. We showed you earlier how to get that code. Once you have entered the code, you can select and customize:

  • How the search results are displayed.
  • A color style for the search elements.
  • Whether to show the search button.
  • Whether a sidebar is displayed on the search page.
  • A theme for the search popup.

So without going back to the Google CSE dashboard, you can customize the look and feel of your website search using this plugin.

If you want to do more advanced customization of your CSE, take a look at the next section to see the options that Google provides.

How to Customize Your Google Custom Search Engine

If you want to really get creative with your CSE, Google provides a wide range of options to help you customize.

Customize the Look and Feel

  • Layout: You can select from multiple layouts for your search engine, including overlay, compact, and results only. Choose the one that best suits your website.
  • Themes: You can choose a design theme for your search engine, such as minimalist.
  • Customize: This tab lets you select the font, border, and background for various search engine elements, such as URLs and buttons.
  • Thumbnails: You can enable or disable thumbnail images in your search results.

Add Search Features

  • Promotions: You can add specific URLs (even external ones) to be promoted whenever users search your site for specified keywords.
  • Refinements: You can enable your users to filter the search results using predefined categories or labels.
  • Autocomplete: Google can generate autocompletion terms for you to help users search your site more quickly.
  • Synonyms: Help your users by adding synonyms to your search engine, so that related terms are searched simultaneously.

A useful feature is the integration with Google Analytics, which will enable you to get detailed statistics and data on how your users are searching your site.


Source: Tom Ewer for Elegant Themes Blog