# Integrating Discourse: Draft Post Issues

**URL:** <https://forum.ghost.org/t/integrating-discourse-draft-post-issues/9622>\
**Category:** Integrations & API\
**Created:** [October 21, 2019, 5:34am UTC](https://forum.ghost.org/t/integrating-discourse-draft-post-issues/9622 "2019-10-21T05:34:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klayemore](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/klayemore/32/3644_2.png) [@Klayemore](https://forum.ghost.org/u/Klayemore)\
**Post date:** [October 21, 2019, 5:34am UTC](https://forum.ghost.org/t/integrating-discourse-draft-post-issues/9622/1 "2019-10-21T05:34:02Z")

</div>

Hi, I’m integrating Discourse with my Ghost blog so that new posts appear on my forum as topics: [Official Ghost + Discourse Integration](https://ghost.org/integrations/discourse/). The topic is created on Discourse after the first page view.

I’m running into a problem though where a new topic is created when a post is in draft mode. Is there any way I can display the JS embed code only if a post is published? Is there some kind of ‘draft’ tag I can use in an #has statement?

Cheers.

---

<div class="post-metadata">

**Author:** ![Stromfeldt](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/stromfeldt/32/13572_2.png) [@Stromfeldt](https://forum.ghost.org/u/Stromfeldt)\
**Post date:** [October 21, 2019, 9:30am UTC](https://forum.ghost.org/t/integrating-discourse-draft-post-issues/9622/2 "2019-10-21T09:30:32Z")

</div>

I had this same problem occur upon updating to Ghost 2.0. Somebody who knows more about this stuff fixed it for me. If you’re using the same Discourse embed code as I am, and looking at my theme’s GitHub repo, you’ll want to replace this portion of the code:

```auto
          DiscourseEmbed = { discourseUrl: 'https://discourse.yourdomain.com/',
                             discourseEmbedUrl: '{{@blog.url}}{{url}}' };
          (function() {
            var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
            d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
          })();

```

with this:

```auto
            if (window.location.pathname.indexOf('/p/') < 0) {
                DiscourseEmbed = { discourseUrl: 'https://discourse.yourdomain.com/',
                                  discourseEmbedUrl: '{{@blog.url}}{{url}}' };
                (function() {
                    var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
                    d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
                    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
                })();
            }

```

I hope that fixes things for you. 🙂

---

<div class="post-metadata">

**Author:** ![Klayemore](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/klayemore/32/3644_2.png) [@Klayemore](https://forum.ghost.org/u/Klayemore)\
**Post date:** [October 21, 2019, 9:52am UTC](https://forum.ghost.org/t/integrating-discourse-draft-post-issues/9622/3 "2019-10-21T09:52:57Z")

</div>

Ahhh that’s a great solution. Thank you 🙂

---

<div class="post-metadata">

**Author:** ![StuartMorrisAU](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/stuartmorrisau/32/26117_2.png) [@StuartMorrisAU](https://forum.ghost.org/u/StuartMorrisAU)\
**Post date:** [January 18, 2020, 7:06am UTC](https://forum.ghost.org/t/integrating-discourse-draft-post-issues/9622/4 "2020-01-18T07:06:56Z")

</div>

Awesome @Stromfeldt! I was initially trying to find a Ghost post status filter to do this via handlebars, but this works a treat. 🙏

---

<div class="post-metadata">

**Author:** ![zeluspudding](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/zeluspudding/32/7069_2.png) [@zeluspudding](https://forum.ghost.org/u/zeluspudding)\
**Post date:** [March 29, 2020, 8:49pm UTC](https://forum.ghost.org/t/integrating-discourse-draft-post-issues/9622/5 "2020-03-29T20:49:31Z")

</div>

@DavidDarnes, or @Kym would you consider updating the [Discourse + Ghost Integration](https://ghost.org/integrations/discourse/) documentation to include the conditional

```auto
if (window.location.pathname.indexOf('/p/') < 0) {
   //discourse embed logic
}

```

to protect future users from auto generating discourse threads on draft views of an article.  
Looks like it’s been a problem for at least 7 users (including me) and the code above fixes it in a jiff 🙂  
PS Ghost IS AMAZING!!

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [March 31, 2020, 8:28am UTC](https://forum.ghost.org/t/integrating-discourse-draft-post-issues/9622/6 "2020-03-31T08:28:34Z")

</div>

Hey @zeluspudding, thanks for this suggestion. We’ve updated our integration page for Discourse if you want to check it out:

> **[Official Ghost + Discourse Integration](https://ghost.org/integrations/discourse/)**
>
> Setting up Discourse with Ghost allows you to embed comment on your posts and pages & link your site to your community forum. Find out how 👉

---

<div class="post-metadata">

**Author:** ![zeluspudding](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/zeluspudding/32/7069_2.png) [@zeluspudding](https://forum.ghost.org/u/zeluspudding)\
**Post date:** [March 31, 2020, 4:29pm UTC](https://forum.ghost.org/t/integrating-discourse-draft-post-issues/9622/7 "2020-03-31T16:29:24Z")

</div>

Bodacious! 🙂
