Removing the ad label from unfilled Google Ad Manager ads

We provide the code snippets and content on this page without any guarantee or support. In most cases, these pages are created on requests or based on individual solutions sent to us by other users. After it was published, we are only reviewing the code and content when we are made aware of an issue. Please let us know if you find one.

Please only use the codes if you understand them and know how to add custom code to your WordPress site.

The following code snippet will hide the ad label if a placement with a Google Ad Manager ad stays empty. You can implement this snippet into the custom code field of a particular ad. It’s best to adjust the script for every ad you use since a few ids and variables must be unique.

Here is the script:

<script type="text/javascript" id="unique-script-id">
	var uniquePlacement = jQuery('#unique-script-id').siblings('[id^="advad-"]'); 
	var uniqueSlot = uniquePlacement.find('[id^="gpt-ad-"]').attr('id'); 
	
	// hide add label
	uniquePlacement.find('[class$="-adlabel"]').hide();
	googletag.cmd.push(function() {
		googletag.pubads().addEventListener('slotOnload', function(event) {
			var slot = event.slot;
			if ( slot.getSlotElementId() == uniqueSlot ) {
				// Show the add label
				uniquePlacement.find('[class$="-adlabel"]').show(); 
			}
		});
	})
</script>Code language: HTML, XML (xml)

We have named all the crucial ids and variables with the word unique. These are the mentioned parts you need to change. You need to set a unique id for the script tag and adjust that in the following code.

Additionally, you need to set unique variables for uniquePlacement and uniqueSlot. These need to be adjusted in a few lines of the code. In jQuery('#unique-script-id').siblings('[id^="advad-"]'); the advad- is the ID prefix, which is set in your WordPress backend at Advanced Ads > Settings. So you might need to change this field too.

Make it better

Increase your ad management skills without spending more time.
Join over 150,000 publishers and AdOpts increasing their ad revenue.