Last active
September 23, 2017 16:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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