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)

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Do you want to use Google search on your WordPress site?

By default, WordPress comes with a built-in search feature, but it is not very good. By adding Google Search in its place, you can display more accurate and relevant search results to visitors.

In this article, we will show you how to easily add Google Search to a WordPress site.

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, let’s see how you can easily add a Google site search to your WordPress site.

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

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.

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.

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

Add new 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. The Google Search form will be automatically added to your site upon activation.

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 pages and posts, 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 for internal search.

It is the best WordPress search plugin on the market that automatically replaces the default search form and allows users to find anything they need on your site.

The SearchWP homepage

SearchWP is used by over 30,000 websites and 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, comments, custom fields, WooCommerce products, and more.

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

Configure SearchWP engine settings

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.

We hope this article helped you learn how to easily add Google Search to a WordPress site. You may also want to see our beginner’s guide on how to get my WordPress site listed on Google and our tips for using Google Search Console to grow website traffic.

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.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

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

81 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Ivo says

    Hi there, thanks for the well-explained method. The only problem I had was after activate and save the snipped I was taken to a page: “403 Forbidden Access to this resource on the server is denied!”. How, I guess I have to do something in my cPanel or have to contact the hosting provider to fix this?
    Regards

  3. Dennis Muthomi says

    Great guide!

    Finding relevant information quickly on a WordPress site can be frustrating with the default search. I’ve been considering integrating either the Google Programmable Search Engine or the SearchWP plugin to improve the search experience for my visitors.

    I’m leaning towards SearchWP for better control over relevancy, but I’m curious if anyone has tips for optimizing its performance on larger sites?

    • WPBeginner Support says

      It would depend on the size of the site, SearchWP has documentation on the plugin’s site for it’s different site size recommendations.

      Admin

  4. Jiří Vaněk says

    This sounds like a very handy alternative to the classic WordPress search. Does it also have any impact on better indexing of the site?

    • WPBeginner Support says

      Indexing of your content would be handled through things like SEO plugins, these search options would not affect your indexing.

      Admin

  5. Cammy says

    Is there a way to set it up so the search results are served on a custom page of my website – i.e. the search results page or one with my sites header and footer?

    • WPBeginner Support says

      That is what the plugin should allow if we understand what you’re looking for correctly

      Admin

    • WPBeginner Support says

      That would depend on your theme. If you reach out to your theme’s support they should be able to assist.

      Admin

  6. Josh says

    How did you get your WordPress search icon via the header to show Google search results? That is actually what I am trying to do and it seems impossible with my scope of skillset. A tutorial would be great but I am sure it wouldn’t be as easy to give a tutorial on something like that. Thank you for this article, though!

    • WPBeginner Support says

      If your theme does not have the option to add a search widget to your header, you would want to reach out to your theme’s support for hot to add it to your specific theme.

      Admin

      • Josh says

        I actually figured it out 10 minutes after sending my comment, of course. It involved two things of code from Google. One code replaced what was in my searchform.php file while placing the other code on the search results page. Super easy, but now I just have to customize the looks so that it looks better with my theme.

        Thanks and regards,

        J

Leave a Reply to Abhisek Cancel 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.

WPBeginner Assistant
How can I help you?

By chatting, you consent to this chat being stored according to our privacy policy and your email will be added to receive weekly WordPress tutorials from WPBeginner.