10

Imagine that one day, suddenly, random ads started appearing on your website...

Recently Disqus started forcing unwanted ads inside of the Disqus comments, displaying those nasty ads on your website(s) without your knowing. It seems that they only target the sites with "big enough" daily traffic or use some other arbitrary criteria, so the ads do not appear on all the websites, but only on relatively busy ones.

This way Disqus "forces" you to upgrade to the paid subscription plan - for the paid users these ads become optional (i.e. you can disable them in your Disqus admin panel).

What to do if you don't want to pay? How to disable these ads? Is there an easy, quick-fix solution for this?

At least until we have the time to switch to another commenting system.

Eric Gopak
  • 1,663
  • 1
  • 13
  • 26
  • doubt there is any way. they're just being sneaky about it which in this case is bad because it's losing customers – L_Church Mar 06 '18 at 13:29
  • 3
    If you like the product then pay for the service or change to another service and voice your opinion so the company knows why their free customers are leaving. – Daniel Gale Mar 06 '18 at 13:29
  • Fair enough, but this came as a changed policy and they did not even notify the respective webadmins before doing so. Hence, a temporarily solution for performing the transition would also be fair. – Eric Gopak Mar 06 '18 at 13:34
  • 1
    I understand your complaint and I'm not saying you are wrong for feeling that way and it would have been nice to be notified about the change. However this is most likely a response to paying for staff and server resources for non-paying users. It may not be the best option but I feel it's fairly standard. – Daniel Gale Mar 06 '18 at 13:39

10 Answers10

11

You can hide the ads iframes with CSS (note that what @DanielGale said is correct - this will be a cat and mouse game, your CSS selector will have to adapt):

iframe[src*="ads-iframe"] { display: none; }
DeanAttali
  • 25,268
  • 10
  • 92
  • 118
6

As of moment of writing, it seems that popular AdBlock browser extensions successfully block the ads. However, not all of your website visitors use adblock.

Here is a quick jQuery-based solution to hide the ads:

(function($){
    setInterval(() => {
        $.each($('iframe'), (arr,x) => {
            let src = $(x).attr('src');
            if (src && src.match(/(ads-iframe)|(disqusads)/gi)) {
                $(x).remove();
            }
        });
    }, 300);
})(jQuery);

Just insert it on your website after jQuery loads, on every page where the Disqus comments appear. The code checks periodically if there are Disqus ads present on your website and removes their container whatsover. You know, just in case if they'll try to re-appear.

Eric Gopak
  • 1,663
  • 1
  • 13
  • 26
6

I was able to remove adds with this simple CSS entry:

div#disqus_thread iframe[sandbox] {
        max-height: 0px !important;
}

This works because the ads are served in an iframe with a 'sandbox' attribute.

Bruce Momjian
  • 61
  • 1
  • 2
4

Disqus has changed over time, since this question was asked. Now in 2021 Disqus uses iframes with indistinguishable class names and ids. I have found that when it displays ads it displays a minimum of 3 iframes, with the 2nd iframe being the comment section itself, the first iframe and iframes after the 2nd are ads. Also Disqus developers are clever, and on the initial load Disqus only loads 1 iframe, being the comment section itself, and after a small delay ~0.5-1s it loads the ads. So you can't remove them with plain CSS anymore, because your CSS will usually load before the Disqus ads load, so we have to write a function with a delay, that waits for the ads to load. Then remove.

Here is my code sample in JQuery, that works for me on different sites:

const disqus = jQuery('#disqus_thread');

disqus.ready(function() {
  setTimeout(function() {
    if (disqus.children().length >= 3) {
      const comments = disqus.find('iframe:nth-child(2)').detach();
      disqus.empty().append(comments);
    }
  }, 2000);
});

I'm searching for the disqus_thread id. Then the function waits for 2s. Usually 1.5s is the longest time it takes for Disqus ads to load. So 2s is a safe spot for waiting ads to load. Then I check for how many children elements does the disqus div has. If it is fewer than 3, it means that Disqus didn't load ads, so we don't have to remove any elements. But if 3 or more children is present, we save the 2nd child which is the comment section, then remove every elements inside the disqus div, and reappend the comment section.

This is not the ideal solution. But it has worked for me so far in multiple websites.

grabovszky
  • 41
  • 2
2

UPDATE: Dec 2021

As of 2021, many of the previous solutions don't work. Here's a simple solution I came up with:

The Disqus ad section comes with an iframe tag which has an attribute sandbox. So you just need to set the display of any iframe element to none that has sandbox defined.

iframe[sandbox]:not([sandbox=""]) {
    display: none !important;
}

Caution: Be careful if you have any other iframe tags defined in your website which has the sandbox attribute. This might remove all of them.

betelgeuse
  • 1,136
  • 3
  • 13
  • 25
1

You can install this plugin for WordPress site: https://wordpress.org/plugins/remove-disqus-ads/

Mowshon
  • 939
  • 9
  • 16
1

You can do it in vanilla javascript

document.addEventListener('DOMContentLoaded', function () {
    let disqus = document.getElementById('disqus_thread');

    let remove_ads = setInterval(() => {
        let iframes = document.getElementsByTagName('iframe');

        for (var iframe in iframes) {
            if (typeof iframes[iframe].src === 'undefined') {
                continue;
            }

            if (iframes[iframe].src.match(/(ads-iframe)|(disqusads)/gi)) {
                iframes[iframe].style.display = 'none';
                disqus.style.width = '100%';
            }
        }
    }, 500);

    setTimeout(function () {
        clearInterval(remove_ads);
    }, 5000);
});
1

After spending about 40 minutes and trying different method I came to solution with the following jquery code snipet. As we know disqus have ad section above and below the comment and all of these are in iframe with id starts like "dsq-app1320" (with only 4 digit variation) so the code snippet is

$(window).on('load', function () {
    $("iframe[id^='dsq-app']").each(function (i, el) {
        if(i===0 || i===2) {
            el.remove();
        };
    });
});
Shishir Subedi
  • 609
  • 3
  • 10
  • Seems good. But does this code work when Disqus is loaded using lazy load? – Ramakrishna S Oct 11 '21 at 18:10
  • @RamakrishnaS I have know idea about that, actually I'm a backend engineer and I was really annoyed with the disqus ads in both upper and lower section of my post's comment. I was looking for solution and posted it here after I got the result. :D – Shishir Subedi Nov 22 '21 at 15:22
0

For disabling ads of "Sponsored" tabs in Disqus section

your problem will solved by this plugin:

https://github.com/Muneebkh2/ads-disabler-disqus

If you have any other query let me know ?

Thanks.

Muneeb
  • 85
  • 1
  • 10
0

Adding this code to<head>tag,has worked in practice.

<style>iframe:not([src]){display: none;}</style>
Wanda
  • 1
  • 1