Topics Map > IT Services > Training
Topics Map > IT Services > Software Support

WordPress - Replacing Search with Google Custom Search

This guide will walk through the steps necessary to create a custom Google search for a WordPress site, replace the WordPress site's native search tool, and formatting the search box and search results page.

Set up a custom search using a Gmail account

The first step is to create a Google Custom Search. This will apply Google's search algorithm and indexing to the WordPress site, and return results that are only from this site.

This will not work for your account--if you were to create a custom search with your uwosh account and later leave the university, the search would be deleted with the rest of your uwosh account and cease to function, so creating custom searches with uwosh accounts has been disabled.

  1. To create a custom search engine, follow Google's instructions
  2. If you are creating this search under a personal Gmail account, click on Setup on the left menu, and then click the Admin tab on top. Here, add the user If you created this search while using the UWOCustomSearch account, there is no need to do this.
    Image shows add user dialog.
  3. Click on the Business link on the left menu and then select the radio button to not show ads on results pages.
    Image shows option to remove ads selected.
  4. Click on Look and feel on the left menu and select Two Page on the Layout tab.
    Image shows two page option selected.

Keep this window/tab open as you'll need to copy code from it.

Create the Google custom search box

  1. Create a new folder anywhere on your computer (your desktop for example) named custom-files
  2. Open up a text editor and paste in this code:

           $gcs = "";

  3. Go to the Google Custom Search tab you kept open and click "Save & Get Code"
    Save & Get Code
  4. Copy the entire code snippet inside the grey box and paste it in between the quotation marks in your text editor.

    Search box code

    Code - text editor

  5. In the last line of the code snippet and type in this attribute to the opening <gcse:searchbox-only> tag: resultsUrl='http://????'

    results url attribute

  6. Replace the question marks with the subdomain that you are creating for this search engine.
  7. Save the file inside your custom-files folder as google-custom-search.php
  8. Using your favorite SFTP program (Transmit is listed below), upload the custom-files folder to the /wp-content folder on your site.

    custom-files folder example

Create a search results page in the WordPress site

This walkthrough assumes that two-step search process is desirable, where a search entered in the search box on any page of the site will take users to a search results page--and this step deals with setting up that page. Other options can be researched and changed within the Google Custom Search tool.
  1. Log into the WordPress site and select Pages > Add New from the menu on the left. 
  2. Title the page "Search Results" and format it to match the other pages of the site.
  3. Create a text module to display the search results in the page.
    ExampleSearch Results Page Example
  4. Once you are ready to display search results, copy this text: <gcse:searchresults-only></gcse:searchresluts-only>
  5. Open up the module you created for the search results.
  6. Select the "Text" tab on the upper right of the content editor of the page.
  7. Paste the text into the content box. This will be the only text needed for this container for the Custom Google Search to display the results. It should look similar to image below.Paste Text into the Content Box
  8. Click update to save the change on the Wordpress page.

Test the new search

View any page of the Word Press site and click the magnifying glass at the top to search the site. A search box should appear with the Google watermark in it. Run a search and make sure that search results displayed are only from this Word Press site, do not include ads, and are readable.

Note: You may need to reload the page once or twice to see the search box come up. If you still don't see it after a few refreshes, try clearing your cache and try it again.

If you need further assistance please contact the Information Technology Help Desk at 920-424-3020 or

Keywords:Guide, "word press", "how to"   Doc ID:56354
Owner:Brian L.Group:UW Oshkosh
Created:2015-09-15 10:57 CDTUpdated:2016-06-22 14:32 CDT
Sites:UW Oshkosh
Feedback:  2   0