Remove blank space and advertisement text on unfilled ad

AI-generated summary

The discussion revolves around removing blank space and advertisement text on unfilled ads in Discourse forums. codergautam pointed out that when Google can’t find an ad, it leaves a blank space with advertisement text, causing confusion. Lilly suggested a workaround to hide the text, but codergautam wanted a solution that only hides the text when an ad is not showing.

codergautam eventually found a solution using CSS and shared a tutorial on how to implement it. However, Firepup650 found a potential issue with Google incorrectly filling out a field, but codergautam clarified that the behavior is consistent.

Firepup650 shared a personal experience where an ad was marked as unfilled but still present, but couldn’t replicate the issue. Canapin warned that the CSS :has selector used in the solution isn’t widely supported, particularly in Firefox.

Ads on my forum dont always fill and sometimes Google isn’t able to find an ad atm, so it just shows blank. This is fine, but I believe the advertisement text and the white space taken during this scenario should be removed since it leads to some confusion (eg. people thinking the above post was a promoted advertisemnt)

I am not sure about the white-space but I think this works for the text:

I guess that is a workaround for now, but the text is now always hidden. I would prefer to have it when an ad is showing, hidden when it’s not. I will mess with the css and see if I can make a selector that runs when ads are empty.

I think it should be theoretically possible since google marks it with this property:

I figured it out!!

It will keep the Advertisement text hidden by default, and only show it after confirming the ad is filled and displayed. This way I can ensure there is no confusion.

If you want to enable this on your forum, take a look at the detailed tutorial I posted on my blog

https://blog.codergautam.dev/how-to-hide-unfilled-advertisements-in-discourse-adplugin/

Edit: using revised version of working code after Firepup found a bug

Hope this helps someone!

Apparently google incorrectly fills out that field (Note the iframe):

And apparently you can’t just check for the iframe either, as sometimes it adds a practically empty iframe.

I can’t cause this anymore, must have been a one-off.

No I tested it a lot, when its unfilled it still adds an iframe but keeps it empty. When its filled however the iframe is populated. It’s not a bug.

There was at least once I manually un-hid the AD, and there was actually an AD there, even though it was marked as unfiled. I couldn’t cause it again after that though.

Just in case you wouldn’t be aware of it, the CSS :has selector isn’t widely supported, notably Firefox: