Why use Google Custom Search Engine in WordPress
The default search feature within WordPress often fails to find relevant results. There are plenty of paid search plugins for WordPress, such as SearchWP. Yet, you need to manage them and they slow down your server resources.
Using Google Custom Search Engine in WordPress is a great alternative.
It consists of the following benefits:
- a reliable and powerful search feature
- that limits the search to your website only
- runs from your own WordPress site
- in a speedy way
- with no maintenance or updates needed
Ways to insert Google Search Engine to WordPress
There are two main ways to add Google Search Engine to WordPress:
- Plugin: Add Google Search to WordPress with a Plugin
- Manual: Add Google Search manually
1. Plugin: Add Google Search in WordPress with a Plugin
The first method is to add Google Search to WordPress with a Plugin.
WP Google Search is a handy plug-in to use without modifying your WordPress theme files. This method suits beginners.
- Visit "Settings" to set up the "WP Google Search" plugin.
- The plugin will ask you to provide a Google Search Engine id.
- Visit the Google Custom Search Engine website.
- Click on the New Search Engine link on the left.
- Provide your "WordPress site’s URL" in the ‘Sites to Search’ field.
- Choose the "language" of your website.
- Click on the "Create" button to continue.
- Click on the ‘Search engine ID’ button.
- Copy your Google custom search engine ID.
- Click on the ‘Look and Feel’ section.
Under the layout tab, select "results only". - Choose "Layout for search results page".
- Click on the "Save" tab at the bottom of the page.
- Log in to your WordPress site.
- Search "Engine ID" in the WP Google Search settings page.
- Click on the "Save changes" button to store plugin settings.
- Visit "Appearance" and go to "Widgets Page".
- Look for "WP Google Search Widget" in the list of available widgets.
- Drag and drop the widget to the sidebar you want to display.
- Click on the "Save" button to store your widget settings.
- Now visit your website to see the Google Search widget in action.
2. Manual: Add Google Search manually
The second method is to add Google Search to WordPress manually. For this, modifying the WordPress theme file is necessary. This method suits advanced users only. Back up your WordPress site before making any changes.
- Visit the Google Custom Search Engine website.
- Click on the New Search Engine link on the left.
- Provide your WordPress site’s URL in the ‘Sites to Search’ field.
- Choose the "language" of your website.
- Click on the "Create" button to continue. Google will now create your custom search engine and will show you a success message with links to further actions.
- Click on the "Get Code" button to continue.
- Copy the code in the text area, you will see on the next screen.
- Connect to your website using FTP.
- Go to the /wp-content/themes/your-current-theme/ folder.
- Replace the theme folder with the name of your current theme.
- Locate the "searchform.php" file in your WordPress theme directory.
- Download this file to your computer.
- Open the file in a plain text editor like Notepad.
- Delete all contents of the file.
- Paste your Google custom search engine code.
- Save the file.
- Upload the file back to your WordPress site using FTP.
- Log in to WordPress. Choose "Appearance" and "Widgets".
- Drag and drop the Search widget to your sidebar.
- Click "Save" to store your widget settings.
- You can now visit your website to see the Google search in action on your WordPress site.
Customize Google Custom Search Engine Layout
After installing Google Custom Search Engine, it is now time to customize the layout in accordance with your website. Here is how to do that:
- Go to the Google Custom Search website.
- Click Edit search engine.
This will show settings for your custom search engine. - Click on "Look and Feel" from the sidebar.
- Choose one of the Google custom search pre-made themes available.
- Click on "customize" to choose your own font, border, and background colours for Google custom search.
- "Save" your changes.
TIP: You don’t need to paste the code again, these changes will be automatically applied to your search form.