Site logo

Archived topic

Google Site Search/Custom Search implementation

39 replies · Started by morriscountynj on January 13, 2017

Viewing posts 31–40 of 40

Hi Leslie,

Thanks for your kind words, and glad the code is helpful! I agree that changing WP's search function should be simpler, given that the default capability is not particularly great...

Interestingly, my site's old theme was originally developed in 2008 and all you had to do to change the search function was enter the CX value of your Google Custom Search Engine into the theme's settings and boom, you were done. Today of course there are more options to choose from, but still, something that's easier to plug-and-play – and without having to figure out custom code – would be very welcome.

To add the code above, I used the Code Snippets plugin (no changes to the theme files themselves and no child theme used either):

https://wordpress.org/plugins/code-snippets/

Hope that helps!

Aahh..I forgot about the code snippets plugin as an option. I already have a child theme so I'll add the code to my child functions.php. Thanks very much for your quick reply. I am thinking I might implement GCSE side-by-side on a staging site, to compare it to GPT-3.

Sure, that will work too. Code Snippets provides an easy way to do it without changing files, but functions.php is great if you already have a child theme in place.

That's cool about a side-by-side comparison – I would be interested in hearing your assessment afterwards!

Great, thanks again.

Yes. Somehow the ".js" suffix got removed from your <script> call... (meaning nothing would happen)

<script async src="https://cse.google.com/cse.js...

Hope that helps!

Thanks. Do I also need to enable Execute PHP?

It looks like you're trying to add the code as an Element. I would suggest using Code Snippets instead. It's an incredibly useful free plugin that replaces the need to modify the functions.php theme file.

https://wordpress.org/plugins/code-snippets/

Add the PHP code into a new snippet then tick "Only run on site front-end."

My site has over two dozen code snippets for various levels of customization, including the custom search engine described above.

This archived topic is closed to new replies.