Advanced Ads offers a couple of filter hooks you can use to change settings, ad output or other things. To learn more about each hook you might take a look into the code or simply experiment a bit. You can learn more about filters from the add_filter page on wordpress.org.

Table of Contents

advanced-ads-activate-advanced-js

Return true to force the advanced js library to be enqueued. Use by add-ons.

advanced-ads-ad-edit-allowed-metaboxes

Use this hook when you want to add new meta boxes to the ad edit screen. We prevent non-Advanced-Ads related meta boxes from showing up here.

advanced-ads-ad-health-display-fine

Manipulate the value of the variable that marks the Ad Health admin menu item as having or not having problems.

advanced-ads-ad-health-show-tcf-notice

Advanced Ads detected that your site uses a Consent Management Platform (CMP) that gathers consent based on the TCF 2.0 standard before showing ads. Enable the TCF integration so that Advanced Ads hides ads until users give their consent.

If this is a false positive then add the following code to your theme’s functions.php to disable the warning.

add_filter( 'advanced-ads-ad-health-show-tcf-notice', '__return_false' );

advanced-ads-ad-image-tag-attributes

Manipulate extra tag attributes for image ads.

advanced-ads-ad-image-tag-style

Manipulate style attribute for image ads.

advanced-ads-ad-list-allowed-columns

Define, which columns are allowed to show up in the ad list in the dashboard.

advanced-ads-ad-notices

Show ad specific notices on meta boxes on the ad edit screen.

advanced-ads-ad-output

Prepare frontend output. You can use the whole ad object with all its parameters to create the output

parameters:

  • string, output that was prepared based on the ad type
  • object, ad object

advanced-ads-ad-output-debug

Filter the output of the ad debug mode.

advanced-ads-ad-privacy-hide-ignore-consent

Set to true to hide the “Ignore general Privacy settings” options appearing on ad edit screens to opt out of consent checks. See TCF 2.0 Consent Manual.

advanced-ads-ad-select-args

Manipulate ad select arguments.

advanced-ads-ad-select-args

Change ad arguments like the display method or the id or add new arguments before the ad display method is started.

parameters:

  • array $args, array with arguments

advanced-ads-ad-select-methods

Manipulate ad select methods.

advanced-ads-ad-select-methods

Ad additional ad selection methods. E.g. if the ad is displayed through a group, the method is group .

parameters:

  • array $methods, array with methods

advanced-ads-ad-settings-pre-save

Manipulate ad settings before being saved.

advanced-ads-ad-types

Applied on an array of ad types. Can add or remove an ad type that later can be chosen when creating an add.

parameters:

  • array $types, array of ad types

advanced-ads-add-ons

Allow add-ons to register for automated update checks.

advanced-ads-admin-max-terms

Limits the number of terms and authors displayed on ad edit pages, e.g. when choosing categories where an ad should be displayed / hidden. If there are more than 50 authors or terms for a given taxonomie, you can only choose them using a search form.

  • int, default: 50

example (use in theme’s functions.php)

add_filter('advanced-ads-admin-max-terms', 'my_advanced_ads_admin_max_terms');
function my_advanced_ads_admin_max_terms($max_terms){
    return 500; // can return any other number here
}

advanced-ads-ads-txt-content

Adjust the content of the ads.txt file generated by Advanced Ads.

advanced-ads-bots

Change the list of blocked bots, user agents and web crawlers. You don’t need to add exact matches to the list. If you have a bot with the user agent My personal botthen adding personalto the list is enough.

The list is used for the option Advanced Ads > Settings > General > Hide ads from bots and used for all clicks in the Tracking add-on.

Example of how to add a new bot to the list. Add it to your theme’s function.php

add_filter('advanced-ads-bots', 'my_advanced_ads_bots');
function my_advanced_ads_bots($bots = array()){
    $bots[] = 'example crawler'; // duplicate this line for each bot
    return $bots;
}

advanced-ads-can-display

Add additional checks whether do display an ad or not.

parameters:

  • bool $can_display, whether to display or not an ad
  • object $ad, ad object

example (use in theme’s functions.php) using this hook to disable ads from non-posts

add_action( 'advanced-ads-can-display', 'advads_show_ads_on_posts_only' );
function advads_show_ads_on_posts_only( $can_display ){
    
    global $post;
    
    if( ! isset( $post->post_type ) || 'post' !== $post->post_type ){
	return false;
    }
    
    return $can_display;
}

other notes

  • in case you don’t want to overwrite previous checks you should only explicitly return false, but if true simply return $can_display

advanced-ads-can-display-placement

Can be used to disable a placement using custom display conditions.

An example shared by a user to disable the after-content placement in posts only:

add_action( 'advanced-ads-can-display-placement', function ( $can_display, $placement_id ){
global $post;
if( in_array( $placement_id, array( 'after-content' ) ) && ( ! isset( $post->post_type ) || 'post' !== $post->post_type ) ){
return false;
}
return $can_display;
}, 100, 2 );

advanced-ads-can-inject-into-content

Can be used to suppress ad injection into the content if set to false.

advanced-ads-can-inject-into-content- $_placement_id

Can be used to suppress ad injection into the content based on the id of the placement.

advanced-ads-capabilities

Manage the list of available capabilities. Currently no use case.

advanced-ads-capability

Manage the output of an individual capability.

advanced-ads-conditions

(deprecated in favor of advanced-ads-display-conditions)

Add or remove ad conditions (conditions on where to display an ad).

parameters:

  • array, ad conditions

advanced-ads-content-injection-nodes-without-ads

Prevent ad injection by content placements into specific elements. Find more details and an example here.

advanced-ads-custom-label

Adjust the markup of the label added optionally in front of the ads.

advanced-ads-dashboard-screens

Manage a list of admin pages that belong to Advanced Ads. Used to display relevant notifications or enqueue scripts only there.

advanced-ads-display-conditions

Add or remove display conditions.

advanced-ads-display-conditions-check-general

Add checks for custom conditions in the General Display Conditions.

advanced-ads-display-conditions-general

Add more conditions to the General Display Conditions.

advanced-ads-export

Manipulate the export.

advanced-ads-frontend-prefix

Adjust the frontend prefix setting, which can also be found through Advanced Ads > Settings > General.

advanced-ads-gadsense-ad-param-data

Allows modification of extra parameters used to render the ad param box. This hook shoud be fired on admin side but also when doing ajax calls.

  • module: gadsense

parameters:

  • arr $extra_params, array of extra parameters used to draw the content of the ad params meta box
  • obj $content, the ad content object
  • obj $ad, the ad object.

advanced-ads-gadsense-ad-param-script

Allows a modification of the list of scripts to be loaded on the ad edit page (every ad of type advanced_ads, not only AdSense).

  • module: gadsense

parameters:

  • array $scripts, associative array of scripts to enqueue on the ad edit page

advanced-ads-gadsense-ad-param-style

Allows a modification of the list of css files to be loaded on the ad edit page

  • module: gadsense

parameters:

  • array $styles, similar to “advanced-ads-gadsense-ad-param-script” filter hook but for styling (.css files)

advanced-ads-gadsense-ad-param-template

Allows a modification of the template file to include in the ad parameter metabox for an AdSense ad.

parameters:

  • string $default_template, full path to template file to load for ad parameters metabox
  • string $content, the post content for this ad (when editing an ad, empty string otherwise)

advanced-ads-gadsense-responsive-output

Allow modification of the output in the frontend. This filter is applied only if the ad is responsive. Should be used in conjunction with the advanced-ads-gadsense-responsive-sizing hook.

  • module: gadsense

parameters:

  • string $output, the front end output for the ad
  • object $ad, the ad object
  • string $pub_id, the AdSense account ID

advanced-ads-gadsense-responsive-sizing

Allows other plugins to use different resizing mode (horizontal, vertical, rectangle). Handling the frontend output, and the backend is left to the developer.

  • module: gadsense

parameters:

  • array $resizing, the default resizing mode for responsive ad (auto and manual CSS)

advanced-ads-geo-upload-dir

Change the upload subdirectory in which the databases are saved. Default is wp-content/uploads/advanced-ads-geo. You can change the /advanced-ads-geo part.

Example

add_filter( 'advanced-ads-geo-upload-dir', 'my_advads_geo_dir' );
function my_advads_geo_dir( $dir ){
    // this would save the files in /wp-content/uploads
    return '';
}

advanced-ads-group-ad-count

Manipulate the number of ads displayed for a group. Used by the Slider add-on.

advanced-ads-group-output

Filter content of a random ad from an ad group. Remember, there are also filters for the ad content that will work before that.

parameters:

  • string $ad->content, the ad content
  • object $this, the ad group object

advanced-ads-group-output-ad-ids

Filter the groups ad ids and their order.

advanced-ads-group-output-array

Filter or manipulate the array with ad outputs before they get imploded. Can be used to alter the group output.

advanced-ads-group-save-atts

Filter additional group attributes before they are saved.

advanced-ads-group-types

Filter available ad group types. Could be used to add new ones.

parameters:

  • array $types, pre-defined group types

advanced-ads-headlines-for-ad-injection

Select headline levels for headline ad injection into content. Default: h2, h3 and h4.

advanced-ads-import

Manipulate import.

advanced-ads-lazy-load-placement-offsets

Set an individual offset for the lazy load feature per placement. See this page for more details and an example.

advanced-ads-list-ad-size

Allows modules to display alternative string for ad size in ads list if required (responsive ads with adsense ad types) when listing ads.

  • string $size, the size string to display in the ad list

parameters:

  • string $size, the size
  • object $ad, the ad object

advanced-ads-notices

Add or manipulate admin notifications.

advanced-ads-options

Manipulate the main plugin options.

advanced-ads-output-final

Used to change or even override the individual ad output completely.

advanced-ads-output-inside-wrapper

Change the ads output before the wrapper is added. E.g. use to add a custom wrapper or change content of the ad dynamically.

parameters:

  • string $output, ad content
  • object $ad, object

advanced-ads-output-wrapper-after-content

Runs inside the ad wrapper after the ad content.

parameters:

  • string, additional output after the ad content
  • object $ad, ad object

advanced-ads-output-wrapper-before-content

Runs inside the ad wrapper before the ad content.

parameters:

  • string, additional output before the ad content
  • object $ad, ad object

advanced-ads-output-wrapper-options

Manipulate wrapper options before the wrapper is built for output; don’t use in case you want to load these options into the ad object

parameters:

  • array $options, wrapper options
  • object $ad, ad object

example

This code will add a class my-ad  to the wrapper. You can use it in your themes functions.php or a custom plugin.

function my_function( $wrapper_options, $ad ){
    $wrapper_options['class'][] = 'my-ad'
    return $wrapper_options;
}
add_filter( 'advanced-ads-output-wrapper-options', 'my_function', 10, 2 );

advanced-ads-placement-content-injection-items

Manipulate the items used by the Post Content placement for content injection.

advanced-ads-placement-content-injection-node

Manipulate the node used by the Post Content placement for content injection.

advanced-ads-placement-content-injection-options

Manipulate options for Post Content placement while injecting the ad into the content.

advanced-ads-placement-options-after-advanced

Attach advanced options for placements.

advanced-ads-placement-types

Change ad placement types available.

advanced-ads-plugin-locale

(deprecated)

Choose another plugin text domain locale.

advanced-ads-post-type-params

Change the ad post type.

advanced-ads-pre-ad-save-{type}

Filter ad content field before saving; based on ad type

parameters:

  • string $output, ad content that is to be saved in the db

advanced-ads-pro-background-selector

Adjust the element used to display the background for the background ad placement. You can find an example here.

advanced-ads-pro-display-condition-url-string

Change the URL which is checked against the URL Parameter display condition. E.g., this allows you to add the main domain to the string.

advanced_ads_pro_duplicate_meta_blacklist

Add post meta keys of post meta data that should not be considered if an ad is duplicated.

advanced-ads-pro-inject-content-selector

Filter the content injection filter for placements in Pro. Written using jQuery selectors.

Example:

add_filter( 'advanced-ads-pro-inject-content-selector', 'my_advads_injection_filter' );
function my_advads_injection_filter( $filter ){
    return '.parent().find("p:not(.other-wrapper p)").filter(function(){return jQuery.trim(this.innerHTML)!==""})';
}

This would ignore the .other-wrapper when checking for available paragraphs and not inject into empty paragraphs.

advanced_ads_pro_output_custom_code

Manipulate the output of the Custom Code option in the frontend.

advanced-ads-sanitize-condition-{type}

Sanitize a specific condition type before being saved

parameters:

  • condition value

There are some custom condition sanitize functions in the class, but you can also add new conditions with their own sanitize functions.

advanced-ads-sanitize-settings

Sanitize plugin settings before being saved.

advanced-ads-selling-email-options

Used to customize the content and additional attributes of emails sent by the Selling Ads add-on. Find additional information here.

advanced-ads-selling-product-tab-ad-types

Allow other than HTML and image ads to be uploaded by advertisers on the ad setup page. Find additional information here.

advanced-ads-set-wrapper

Add wrapper options when ad is loaded

parameters:

  • array $options, wrapper options
  • object $ad, ad object

advanced-ads-setting-tabs

Add or manipulate setting tabs.

parameters:

  • array, options of default or already registered setting tabs

advanced-ads-support-messages

Messages shown on the support page in the plugin menu.

advanced-ads-tags-for-injection

Manipulate tags used by the Post Content placement for ad injection into the content.

advanced-ads-tracking-click-tracking-url

Change the click tracking URL created by Advanced Ads Tracking.

advanced-ads-tracking-click-url-base

Change the tracking link dynamically. There is currently no included action to check the manipulated link later, so you might need to add your own redirect.

  • file: public/public.php

parameters:

  • $linkbase – the default or option set link base
  • $ad– the ad object

advanced-ads-tracking-dbop-capability

Change the capability a user must have in order to see the tracking database management options.

add_filter( 'advanced-ads-tracking-dbop-capability', 'advads_adjust_tracking_db_capability');
/**
* Change the capability that can make adjustment to tracking tables.
*
* @return string new capability
*/
function advads_adjust_tracking_db_capability( $cap ){
return 'advanced_ads_manage_options';
}

advanced-ads-tracking-redirect-url

Change the target URL when clicked on a tracking link.

advanced-ads-update-placements

Runs when placements are saved.

advanced-ads-visitor-conditions

Add or change visitor conditions.