Use the URL Parameters condition to check the domain

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 URL Parameters display condition allows you to display ads based on parameters in the URL, e.g., you would use that condition if you wanted to display an ad only on pages that contain the word “domain”, like https://wpadvancedads.com/manual/url-parameters-condition-check-the-domain.

By default, the condition does not check the domain, e.g. wpadvancedads.com.

You could use the code below to add the domain name to the string that is checked against the URL parameters condition.

The code works only for ads that use a placement.

/**
 * Add domain to the path that is checked for the URL Parameters condition when the ad is delivered using a placement.
 */
add_filter( 'advanced-ads-ad-select-args', function( $args ){
	// Add referrer if this is an ajax placement
	if ( isset( $args['url_parameter'] ) && $args['method'] === Advanced_Ads_Select::PLACEMENT && isset( $_SERVER['SERVER_NAME'] ) && '' !== $_SERVER['SERVER_NAME'] ) {
		$args['url_parameter'] = $_SERVER['SERVER_NAME'] . $args['url_parameter'];
	}

	return $args;
} );Code language: PHP (php)

We have seen only very few use cases for this, like when a single WordPress installation is pushed automatically to multiple domains. This is often connected with multilingual sites.

Make it better

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