# AddEvent code not working in Discourse

**URL:** <https://meta.discourse.org/t/addevent-code-not-working-in-discourse/171769>\
**Category:** Product Support\
**Created:** [November 30, 2020, 6:07pm UTC](https://meta.discourse.org/t/addevent-code-not-working-in-discourse/171769 "2020-11-30T18:07:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)\
**Post date:** [November 30, 2020, 9:16pm UTC](https://meta.discourse.org/t/addevent-code-not-working-in-discourse/171769/2 "2020-11-30T21:16:46Z")

</div>

The cause here is that Discourse filters user input in posts as a security measure. You wouldn’t want random users to run scripts on your site, so we filter them out.

You can use a theme component to make this work. If you add something like this in a new theme component - under the header tab - and then add it to your active theme, you’ll be able to use that embed.

```xml
<script type="text/discourse-plugin" version="0.8">
  const loadScript = require("discourse/lib/load-script").default;
  const { next } = require("@ember/runloop");

  api.decorateCookedElement(
    post => {
      const calendars = post.querySelectorAll(`[data-wrap="addEvent"]`);
      if (!calendars.length) return;

      calendars.forEach(calendar => {
        const wrapper = document.createElement("div");
        wrapper.dataset.calendar = calendar.dataset.calendar;
        wrapper.dataset.configure = false;
        wrapper.classList.add("ae-emd-cal");
        calendar.append(wrapper);
      });

      next(() =>
        loadScript("https://addevent.com/js/cal.embed.t1.init.js")
      );
    },
    { id: "AddEvent decorator", onlyStream: true }
  );
</script>

```

Once you do that, you can add the addEvent calendar to a post by adding something like this in your post.

```markdown
[wrap=addEvent calendar=bJ306355][/wrap]

```

You can change the `calendar=bJ306355` attribute to add the specific identifier for the calendar you want to embed.

The last thing you need to do is whitelist the AddEvent script in your site setting (this is another security layer).

Search for the `content_security_policy_script_src` in the admin and add this link there

```plaintext
https://addevent.com

```

Let me know if this works for you, and I can package it as a theme component.

---

_[View the full topic](https://meta.discourse.org/t/addevent-code-not-working-in-discourse/171769)._
