Embedding Discourse Comments via Javascript

That’s a tricky one, because I can’t share details about our customer’s sites. There are some more details about this issue in this topic: Add option to set canonical_url to embed_url. I’ve asked in that topic to see if anyone wants to provide details about how enabling the setting has affected their SEO.

1 Like

Is changing the title enough? The post content would still be shared.

for some reason I can’t even view the page, even with disabled Adblock writes that it needs to be disabled

A single paragraph of “duplication” isn’t enough to trigger any duplicate content problems in my experience – since you used a screenshot from my blog :wink:

It’s similar to quoting a paragraph from a random article.

I did try this today by putting the page url into a hidden div. The script just put the link in place as text. No one box sadly. :frowning:

I was able to get the embed feature to grab my photos from the page. The problem was on my end as the code was using a pre-load/fade-in image JavaScript called lazyload. Once this was removed the topic creation was able to create any image I setup in the class selector area. However…

The topic is created and works fine for a few minutes. The image is viewable via zoom click. But after a few minutes on re-fresh the topic changes and instead of the image being present there is a upload text line in place of the image.


It would appear this is a failure of the image to remote upload to the forums server. Any ideas on why that would fail? Also if it does fail, why isn’t the system just retaining the original URL location. Seems odd.

I should add this wasn’t a lone case either. It consistently happened on all of the topics that had the image initially there (about 10+ topics).

[update: The workaround for this was to add my sites to the blacklist for sites to not download images from. That way the HTML just grabs them from the remote site. Works for me.]

1 Like

Can we prevent new topics when the URL changes (for blog title updates)?

1 Like

Yes, but your blog software will need to keep track of the topic ID that was created on the first call and pass it as a parameter on subsequent embed requests.

See “Linking to existing topics” in the OP.


I am unable to embed via typescript in angular, Please help

let   window : any;

      window.DiscourseEmbed = { discourseUrl: 'xyz.com',

        topicId: 26};


        let script = this._renderer2.createElement('script');

        script.type = "text/javascript";

        script.src =  'window.DiscourseEmbed.discourseUrl '+ 'javascripts/embed.js';

        script.async = true;
this._renderer2.appendChild(this._document.body, script);
1 Like

Is there a way to find the associated topic ID or discourse URL for a given page with discourse embedding? I’d like to provide the discourse URL for our schema.org discussionUrl json-ld that we include in our pages with embedded comments. E.g.,




1 Like

Yes, we have a dedicated API endpoint just for that. Here is an example:

curl 'https://meta.discourse.org/embed/info?embed_url=https://blog.discourse.org/2021/04/discourse-team-grows-to-50' -H 'API-KEY: logapikeygoeshere' -H 'API-USERNAME: apiusernamehere' 

And the response is:

  "topic_id": 187794,
  "post_id": 925017,
  "topic_slug": "discourse-team-grows-to-50-blog",
  "comment_count": 2

Good question, added it to the OP.


Hey all - I’ve been following this topic and trying to get a feel for how the “Imported topics will be unlisted until there is a reply.” function works –

Essentially I have embedded a discourse topic on a webpage sucessfully ----- but want to have the embedded page show all posts in the topic – not just replies to the original post

shouldn’t the “Imported topics will be unlisted until there is a reply.” do this? I’ve tried enabling / disabling this and the “truncate posts” option and don’t seem to notice a difference for either

–any pointers? Thanks in advance


update: I found this topic along with a discourse plugin written by @arivanandan (thank you!) – will attempt to implement and post update for posterity

update 2: Plugin works! Huge thanks again to @arivanandan!!



Is it possible to embed a summary of a user stats? ilke:


  • 240 days visited

  • 6d read time

  • 4d recent read time

  • 1.5k topics viewed

  • 9.1k posts read

  • 539 given


  • 38 topics created

  • 1.2k posts created

  • 320 received

  • 61 solutions


This describes our current use case. Everything works as expected when users are logged into both sites.

The problem I have is that if the user is not logged into our discourse instance (which has no anonymous access) then they don’t see anything on the page where the embed has been places.

Is it possible to get the embed to display a “Login to Discourse to see the discussion” message when this occurs?


I had a similar situation in a instance, and what solved for me was having both sites under the same Identity Provider using DiscourseConnect - Official Single-Sign-On for Discourse (sso).


Thanks, but that’s not possible in this case.

The current behaviour seems odd though because if there is a problem with logins then the user sees nothing. Is there a reason not to show a login link which would redirect to the discourse site?


I’m experiencing the same issue. It would be nice to see the embedded comments even if the site is set to private mode. Overall, I am loving Discourse, and the ability to add the comments to Ghost is a plus!

1 Like

Is there a way to pass a unique div id each time the script is called? I have asynchronous content loading under my main article and would like the comments to appear on those items as well. Of course the issue with the current set up is that they all get shown in the ‘discourse-comments’ div id.

Thanks. @eviltrout

1 Like

There is no way to pass a dynamic id. I’d accept a PR to do that though!

@eviltrout Err… well I know what a PR is (now), but how do you initiate a pull request?