Skip to content

Instantly share code, notes, and snippets.

@paulwellnerbou
Last active September 23, 2017 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulwellnerbou/e0375e226c497efafeb71cc9d79601ee to your computer and use it in GitHub Desktop.
Save paulwellnerbou/e0375e226c497efafeb71cc9d79601ee to your computer and use it in GitHub Desktop.
Snippet to integrate Disqus in your Ghost blog without touching the templates of your theme
<!-- Put this snippet in your "Blog footer" via Ghost's "Code Injection" -->
<script>
// Your Disqus name
var disqusName = 'paulwellnerbou';
// The element where to append the Disqus discussion container, for Ghost 0.11 and the casper theme this is '.post-content'
var elementToAppendDisqusContainer = '.post-content';
var postContent = document.querySelector(elementToAppendDisqusContainer);
if(postContent !== null) {
var div = document.createElement('div');
div.setAttribute('id', 'disqus_thread');
postContent.append(div);
var canonical = document.querySelector('link[rel=canonical]').getAttribute('href')
var identifier = canonical.slice(canonical.slice(0, -1).lastIndexOf('/') + 1, -1);
var disqus_config = function () {
this.page.url = canonical;
this.page.identifier = identifier;
};
(function() {
var d = document, s = d.createElement('script');
s.src = 'https://' + disqusName + '.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment