This guide explains how to embed and display a list of Discourse topics on external websites using JavaScript.
Required user level: Administrator
Summary
Embedding Discourse topics on external websites allows you to showcase forum content such as discussions or announcements. This integration enables you to display topic lists from your Discourse forum directly on your blog, website, or external content platform.
Enable topic embedding
- Add the embedding script to your external site:
<script src="https://discourse.example.com/javascripts/embed-topics.js"></script>
Replace discourse.example.com
with your Discourse forumās URL.
- Place the topics list element where you want to display topics (a blog post, an individual site page, etc.):
<d-topics-list discourse-url="https://discourse.example.com" category="1234" per-page="5"></d-topics-list>
-
Navigate to your siteās admin settings and enable the
embed topics list
site setting panel -
Add your external siteās domain to Admin > Customize > Embedding > Allowed Hosts
You cannot embed topics from a private login-required Discourse site.
Configuration parameters
The d-topics-list
element supports these attributes:
-
template
- Display style options:-
basic
(default) - Shows minimal topic information -
complete
- Shows title, username, avatar, creation date, and thumbnail
-
-
per-page
- Number of topics to display -
category
- Category ID to filter topics -
allow-create
- When true, shows a āNew Topicā button -
tags
- Filter topics by specific tags -
top_period
- Show top topics from a time period:all
yearly
quarterly
monthly
weekly
daily
You can combine multiple parameters to refine your topic list.
Customizing the appearance
You can style the embedded topics using custom SCSS in your Admin > Customize > Themes > Embedded CSS settings:
Example SCSS for a grid layout:
.topics-list {
display: grid;
grid-template-columns: repeat(2, 1fr);
.topic-list-item {
.main-link {
border: 1px dotted gray;
padding: 0;
}
.topic-column-wrapper {
flex-direction: column-reverse;
.topic-column.details-column {
width: 100%;
}
.topic-column.featured-image-column .topic-featured-image img {
max-width: initial;
max-height: initial;
width: 100%;
}
}
}
}
Additional information
SameSite behavior
In SameSite contexts (where the embedding site and forum share a parent domain), Discourse will respect login status and display results accordingly. This means logged-in users may see content from secure categories that anonymous users cannot access.
Working with iframes
The embedded topics list does not use an iframe - it uses a JavaScript widget included via a <script>
tag. This allows for better integration with your siteās DOM structure and easier customization through CSS.
If youāre looking to embed comments rather than topic lists, see our guide on embedding Discourse comments.
Example implementation
You can view a live example of embedded topics and examine the source code:
Last edited by @jessii 2024-11-21T19:01:02Z
Check document
Perform check on document: