Prevent automatic injection into specific elements

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 example for the advanced-ads-content-injection-nodes-without-ads filter shows you how you can prevent ad injection by content placements into specific elements.

Any element that has the do-not-inject-here ID will be excluded from ad injection.

add_filter( 'advanced-ads-content-injection-nodes-without-ads', 'my_content_injection_exclude_nodes' );
function my_content_injection_exclude_nodes( $nodes ){
	
	$nodes[] = array(
		'node' => '#do-not-inject-here',
		'type' => 'ancestor',
	);
	
	return $nodes;
}Code language: PHP (php)

You can use different values for node:

  • use any ID with a preceding #
  • use any class with a preceding .. This will target all elements with the given class, not just one
  • add % do the end of the node’s name to target any element starting with a specific string, e.g., .element-%

At the current state, only single selectors are supported and not combined ones.

Make it better

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