Configuring allowed embed selectors

:bookmark: This guide explains how to configure the ‘allowed embed selectors’ setting in Discourse. This setting is crucial when publishing posts from an external site to Discourse or when embedding Discourse comments on an external site using JavaScript.

:person_raising_hand: Required user level: Administrator

:computer: Some CSS knowledge is required for more avdanced usage

When publishing posts to Discourse from an external site or embedding Discourse comments on an external site, you may encounter issues with the “Show Full Post” button not pulling the correct content. This guide will help you configure the ‘allowed embed selectors’ setting to resolve this issue.

Understanding the problem

When users click the “Show Full Post” button, Discourse may not pull the correct post content from your external site. This is where the ‘allowed embed selectors’ setting comes into play.

Locating the setting

You can find the ‘allowed embed selectors’ setting in two places:

  1. Search for “allowed embed selectors” on your site settings page.
  2. Navigate to Admin > Customize > Embedding, and look for “CSS selector for elements that are allowed in embeds” in the Crawler Settings section.

Identifying the correct CSS selectors

To find the appropriate CSS selectors:

  1. Go to a post on your external site that you’ve published to Discourse.
  2. Open your browser’s web inspector and examine the post’s HTML structure.
  3. Identify the HTML elements that immediately surround the main post content.

For example, in a typical WordPress post, the content is often in a .entry-content div within article tags. In this case, you might use article .entry-content as your CSS selector.

Configuring the setting

To pull various content types from your external site, you may need to add multiple selectors. For instance:

article .entry-content img, article .entry-content p, article .entry-content ul

This example targets images, paragraphs, and unordered lists within the article’s entry content.

Testing and troubleshooting

Finding the correct selectors may require some trial and error. Keep in mind:

  1. Discourse caches external post content for 10 minutes, so changes may not be immediately visible.
  2. To work around this, test with multiple posts or clear the cache on a development site using Rails.cache.clear in the Rails console.

Handling images

If you’re having trouble pulling images from your website, ensure that your CSS selectors include the appropriate image elements. For example:

article .entry-content img

This selector targets images within the article’s entry content.

Additional considerations

  • The ‘allowed embed selectors’ setting applies to both posts published via the API and posts pulled in with the Discourse embed script.
  • You may need to adjust the selectors based on your specific website structure and content types.
  • Remember to save your changes after updating the setting.

Last edited by @hugh 2024-07-16T03:51:58Z

Last checked by @hugh 2024-07-16T03:52:03Z

Check documentPerform check on document:
14 Likes

Can pull images on my website?. I not see images?

It should be possible to pull in images from your website. It can take some trial and error to find the correct CSS selectors to add to your allowed embed selectors site setting.

2 Likes

Yes it work and we can add images of rss to title post auto.