Disqus doesn't work anymore, how can I fix that? #31
-
As the simple Disqus snippet below. <script>
const disqus_shortname = 'YOUR_SHORTNAME';
const disqus_identifier = 'PAGE_ID';
const disqus_url = 'PAGE_URL';
const disqus_script = 'embed.js';
(function(d,s) {
s = d.createElement('script');s.async=1;s.src = '//' + disqus_shortname + '.disqus.com/'+disqus_script;
(d.getElementsByTagName('head')[0]).appendChild(s);
})(document)
</script> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Below shows 3 methods you may choose from. In a refresh area (method 1)
<div class="pjax"><!-- needs to be here on every Pjax page, even if empty -->
<!-- if (some condition) { // eventual server-side test to know whether or not you include this script -->
<script>
const disqus_shortname = 'YOUR_SHORTNAME';
const disqus_identifier = 'PAGE_ID';
const disqus_url = 'PAGE_URL';
const disqus_script = 'embed.js';
// here we will only load the disqus <script> if not already loaded
if (!window.DISQUS) {
(function(d,s) {
s = d.createElement('script');s.async=1;s.src = '//' + disqus_shortname + '.disqus.com/'+disqus_script;
(d.getElementsByTagName('head')[0]).appendChild(s);
})(document)
}
// if disqus <script> is already loaded, we just reset disqus the right way
// see https://help.disqus.com/developer/using-disqus-on-ajax-sites
else {
DISQUS.reset({
reload: true,
config: function () {
this.page.identifier = disqus_identifier
this.page.url = disqus_url
}
})
}
</script>
<!-- } -->
</div> Be a refresh script (method 2)If you dislike wrapping the Disqus snippet in the way of method 1, you may:
<script data-pjax>
const disqus_shortname = 'YOUR_SHORTNAME';
const disqus_identifier = 'PAGE_ID';
const disqus_url = 'PAGE_URL';
const disqus_script = 'embed.js';
// Earlier defined variable indicating whether or not you run this part.
if (someCondition) {
// Only load Disqus if haven't.
if (!window.DISQUS) {
(function(d,s) {
s = d.createElement('script');s.async=1;s.src = '//' + disqus_shortname + '.disqus.com/'+disqus_script;
(d.getElementsByTagName('head')[0]).appendChild(s);
})(document)
}
// Disqus initialized, we just reset it the right way.
// see https://help.disqus.com/developer/using-disqus-on-ajax-sites
else {
DISQUS.reset({
reload: true,
config: function () {
this.page.identifier = disqus_identifier
this.page.url = disqus_url
}
})
}
}
</script> Use a refresh listener (method 3)
<script>
const disqus_shortname = 'YOUR_SHORTNAME';
const disqus_identifier = 'PAGE_ID';
const disqus_url = 'PAGE_URL';
const disqus_script = 'embed.js';
const disqus_load = () => {
// Earlier defined variable indicating whether or not you run this part.
if (!someCondition) return;
// Only load Disqus if haven't.
if (!window.DISQUS) {
(function(d,s) {
s = d.createElement('script');s.async=1;s.src = '//' + disqus_shortname + '.disqus.com/'+disqus_script;
(d.getElementsByTagName('head')[0]).appendChild(s);
})(document)
}
// Disqus initialized, we just reset it the right way.
// see https://help.disqus.com/developer/using-disqus-on-ajax-sites
else {
DISQUS.reset({
reload: true,
config: function () {
this.page.identifier = disqus_identifier
this.page.url = disqus_url
}
})
}
};
disqus_load();
document.addEventListener('pjax:success', disqus_load);
</script> |
Beta Was this translation helpful? Give feedback.
Below shows 3 methods you may choose from.
In a refresh area (method 1)
Wrap your Disqus snippet into a DOM element that you will add to the
selector
option (or just wrap it withclass=".pjax"
). Make sure to have at least an empty wrapper on each page (to avoid differences of DOM between pages).Edit your Disqus snippet like below.