How to add Google Custom Search Engine to Discourse

I want to add Google Custom Search Engine to my forum. Could you please suggest, where and how to add the Custom Search Engine Code to discourse.

Discourse already comes with a pretty powerful search feature. Why would you want to add Google custom search engine?

1 Like

Yeah have to agree, Discourse search works well. I’ve never found a Google custom search implementation that worked well. Even if wanting ad revenue from it I think it would be a negative Impact overall.

I believe there is nothing wrong in trying it out and see the revenue impact. If things wont work, we can switch back anytime. But, how to implement is what I wanted to figure out.
Could someone help me here.

I can’t imagine it would be easy to override the built in search functionality of Discourse. It’s tightly knit into the very foundation of the Discourse app and works at the database level.

Google custom search as far as I’m aware will just build an index of the static site content, it would be a lot worse than what’s already there. Not to mention how you would integrate it into the Discourse UI (the Ember app) :man_shrugging:

I really don’t know how you would make it work (or why you’d want to!)

1 Like

You may need to build a theme component to replace/modify the default search compoment or widget with what your want.

1 Like

I’m not particularly familiar with Google Custom Search, but my understanding is that it would only be able to search public topics. Assuming that’s true, that means your users won’t be able to search their PMs, topics in non-public categories, tags/users/groups (we block indexing for those pages), etc. If there’s a way to give Google admin access to your site, that may solve some issues, but opens up other (privacy) issues.

We do support Algolia, see Add Algolia search to your Discourse.


I’m fairly sure that it only includes pages that are indexed by G also. Which is often only a small % for UGC.

It is not necessary nor a good idea to replace the internal discourse search functionality.

However, there is nothing wrong with adding an additional search capability, Google or otherwise.

This is best done with a plugin and its own route / page.

My advice @KranthiKiranGude is to leave the discourse search feature as-is and create a plugin with a distinct page / route for GCS.

That is exactly what we did with our old LAMP forum, BTW.


@neounix: I am not trying to override the existing search functionality of discourse. I am just trying to add a widget or a plugin, I would be great, if some could suggest how to add a custom HTML component like Google Custom Search Engine to all the pages. I would keep the existing search functionality of discourse as-is. Just wanted to check the revenue impact.

1 Like

Hi @KranthiKiranGude

Based on prior experience implementing GCSE on a forum application, I suggest two plugins:

  1. Theme component for the GCSE search bar. You can then place these GCSE search bars where ever you want on your site. This is fairly simple to do.

  2. Plugin to create a Discourse page (route) to display your GCSE search results. This will be a bit more complicated than the theme component (to show the search bar); so you might want to post in the Meta Marketplace and ask one of the fine Discourse plugin developers to assist you.

If you go this route, please do consider sharing this plugin with the community here.



Hi @neounix,

Could you please help me with a sample code snippet for you suggestion 1. I have tried pasting GCSE Code in section in the theme, but It is not visible, when I previewed it.

Thank You.

Hey @KranthiKiranGude

The link below is a good starting place. You can also enjoy searching meta for the keywords, “theme component”.

See also:

And also (sample code):


I have included the GCSE script in " Edit CSS/HTML" section. But, The search box is not appearing. I could see the code in page source. But, the element is not visible on the UI