How to Add Google Search in WordPress

Tutorials 0 lượt xem

The default WordPress search feature is not good. Search results are often inaccurate. This makes it difficult for your website users to find content that matches their query.

That’s why many website owners have added Google Search to their websites. In this way they take advantage of the power of the largest search engine on the Internet. Now users can easily find the content they want.

In this article, I will show you 2 ways to add Google Search in WordPress

Method 1: Add Google Search with plugin

The method is suitable for beginners. You can easily add Google Search in WordPress without editing the code.

First you need to install and activate the WP Google Search plugin . 

Immediately upon activation, you need to go to Settings -> WP Google Search to configure the plugin.


google search 1

You will be asked to enter your Google Search Engine ID. This is how you get the Search Engine ID.

Go to Google Custom Search and click on the New Search Engine link on the left.


google search 2

Enter your site’s address in the ‘ Sites to Search ‘ field. Next, choose the language for your website. Finally, click the Create button to continue.

Google will create a custom search engine and display a success message with many other options. You need to click on the Control Panel button to continue editing your search engine.


google search 3

On the next screen, click the Search Engine ID button and copy your ID.


google search 4

Next, you need to click on the “ Look and feel ” section on the left. Under the layout tab, select results only.


google search 5

As soon as you’re done, click the Save button at the bottom of the page to save your changes.

Now go back to your WordPress site. Paste the search engine ID you copied above into the settings page of WP Google Search. Then click the Save changes button to save the plugin’s settings.

Then you need to go to Appearance -> Widgets . Here you will see WP Google Search Widget in the widgets list. Drag and drop this widget to the sidebar where you want to display the search form


google search 6

Click the Save button to save the widget settings.

You can now visit your website to check if the search form is working


google search 7

Method 2: Manually Add Google Search in WordPress

This approach is not for beginners. Because you have to change your WordPress theme.

First you also create a Search Engine like method 1. But now in the Look and field screen , you choose Two page


google search 10

Next, we click on Setup on the left. Scroll down and click the Get code button


google search 11

We have 2 pieces of code. A code snippet to create a search form. The rest of the code is used for the search results page.

Next, you need to create a search results page. Simply create a new page. On the page creation screen, enter the name of the page. Switch to the text tab and paste the code for the search form. Finally click the Publish button.


google search 13

Next, you need to replace the default WordPress search form with the Google search form. Go to cPanel and open File Manager. Check out my cPanel manual if you’re new to cPanel.

Navigate to /wp-content/themes/your-current-theme/ directory . Replace your current theme value with your theme name. Locate the file searchform.php . If you don’t have this file you can create one. Otherwise you change the existing file name to create a backup, and create a new file.


google search 18

Open the file you just created and paste the code for the search form. You need to change the code a bit by adding the resultsUrl property . Its value is the search results page path you created above.


google search 15

Now go to Appearance -> Widgets . You drag and drop the default WordPress Search widget to the sidebar you want to display. Finally, you visit your website and check the search form in action.

Hopefully with this article you already know how to add Google Search in WordPress.

If you liked this article, please share it with your friends on social networks.

To receive the latest tutorials, don’t forget to sign up for your email.

If you have problems with adding Google Search to your site, leave your questions in the comments section below.

Bài viết liên quan