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 uwosh.edu 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.
- To create a custom search engine, follow Google's instructions.
- 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 UWOCustomSearch@gmail.com. If you created this search while using the UWOCustomSearch account, there is no need to do this.
- Click on the Business link on the left menu and then select the radio button to not show ads on results pages.
- Click on Look and feel on the left menu and select Two Page on the Layout tab.
Keep this window/tab open as you'll need to copy code from it.
Create the Google custom search box
- Create a new folder anywhere on your computer (your desktop for example) named custom-files
- Open up a text editor and paste in this code:
$gcs = "";
- Go to the Google Custom Search tab you kept open and click "Save & Get Code"
- Copy the entire code snippet inside the grey box and paste it in between the quotation marks in your text editor.
- In the last line of the code snippet and type in this attribute to the opening <gcse:searchbox-only> tag: resultsUrl='http://????.uwosh.edu/search-results/'
- Replace the question marks with the subdomain that you are creating for this search engine.
- Save the file inside your custom-files folder as google-custom-search.php
- Using your favorite SFTP program (Transmit is listed below), upload the custom-files folder to the /wp-content folder on your site.
Create a search results page in the WordPress site
- Log into the WordPress site and select Pages > Add New from the menu on the left.
- Title the page "Search Results" and format it to match the other pages of the site.
- Create a text module to display the search results in the page.
- Once you are ready to display search results, copy this text: <gcse:searchresults-only></gcse:searchresluts-only>
- Open up the module you created for the search results.
- Select the "Text" tab on the upper right of the content editor of the page.
- 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.
- 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 firstname.lastname@example.org