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 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-admin-options
Allows add-ons to add their setting to an array, so the Ad Admin user role (Pro) can save them.
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-edit-show-placement-injection
Set to false
to hide the placement choice that shows up on the ad edit page right after an ad was published. Simply use the following code to do that.
add_filter( 'advanced-ads-ad-edit-show-placement-injection', '__return_false');
Code language: JavaScript (javascript)
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.2 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' );
Code language: JavaScript (javascript)
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-option-{$field}
Filter ad-specific options.
E.g., use the following code to programmatically set the Debug Mode option to true for all ads.
add_filter( 'advanced-ads-ad-option-output.debugmode', '__return_true' );
Code language: JavaScript (javascript)
Note: This might also apply to the option on the ad edit screen. E.g., if you are using the code above, the Debug Mode option on the ad edit screens will by enabled by default, and saving it would keep it also enabled when you remove the filter.
This filter also only works when $ad->option( $field )
is used in Advanced Ads, which is a work-in-progress.
advanced-ads-ad-option-tracking.cloaking
Set to true
to force link cloaking for Advanced Ads Tracking.
add_filter( 'advanced-ads-ad-option-tracking.cloaking', '__return_true' );
Code language: JavaScript (javascript)
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
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
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-add-ons-updater
Set to false
to disable checks for premium plugin updates in WP Admin.
add_filter( 'advanced-ads-add-ons-updater', '__return_false' );
Code language: JavaScript (javascript)
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 taxonomy, you can only choose them using a search form.
- int, default: 50
example (use in theme’s functions.php
)
function my_advanced_ads_admin_max_terms($max_terms){
return 500; // can return any other number here
}
add_filter('advanced-ads-admin-max-terms', 'my_advanced_ads_admin_max_terms');
Code language: PHP (php)
advanced-ads-ads-txt-content
Adjust the content of the ads.txt file generated by Advanced Ads.
advanced-ads-adsense-publisher-id
Removes the client
attribute from Google AdSense codes. See Is the new crossorigin attribute speeding up AdSense ads?
add_filter( 'advanced-ads-adsense-publisher-id', '__return_false' );
Code language: JavaScript (javascript)
advanced-ads-attribution
Manipulate the “Managing ads with Advanced Ads” attribution in the source code. Use the following to remove it entirely.
add_filter( 'advanced-ads-attribution', '__return_empty_string' );
Code language: JavaScript (javascript)
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 bot
then adding personal
to 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
function my_advanced_ads_bots($bots = array()){
$bots[] = 'example crawler'; // duplicate this line for each bot
return $bots;
}
add_filter('advanced-ads-bots', 'my_advanced_ads_bots');
Code language: PHP (php)
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
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;
}
add_action( 'advanced-ads-can-display', 'advads_show_ads_on_posts_only' );
Code language: PHP (php)
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 );
Code language: PHP (php)
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-disable-shortcode-button
Set to true
if you want to remove the button that helps placing ad shortcodes manually in TinyMCE editors (e.g., Classic Editor).
add_filter( 'advanced-ads-disable-shortcode-button', '__return_true' );
Code language: JavaScript (javascript)
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-gam-ad-import-limit
By default, the Google Ad Manager integration loads all ad units from a newly connected GAM account when the account has less than 50. This is also the threshold when offering to import all ad units on the settings page. Use the following filter to change that.
add_filter( 'advanced-ads-gam-ad-import-limit', function(){ return 50; } );
Code language: JavaScript (javascript)
advanced-ads-gam-ad-import-title
Change the ad name when importing ad units from Google Ad Manager automatically.
advanced-ads-geo-maxmind-geolite2-city-db-filepath
Adjust the database file to load and return the absolute path to the city file. You need to add both filters, advanced-ads-geo-maxmind-geolite2-city-db-filepath
and advanced-ads-geo-maxmind-geolite2-country-db-filepath
to your theme’s functions.php
. It won’t work if you embed only one of them.
Example:
add_filter( 'advanced-ads-geo-maxmind-geolite2-country-db-filepath', function(){
return WP_CONTENT_DIR . 'uploads/geolite2/Country.mmdb';
} );
add_filter( 'advanced-ads-geo-maxmind-geolite2-city-db-filepath', function(){
return WP_CONTENT_DIR . 'uploads/geolite2/City.mmdb';
} );
Code language: JavaScript (javascript)
advanced-ads-geo-maxmind-geolite2-country-db-filepath
Adjust the database file to load and return the absolute path to the country file. You need to add both filters, advanced-ads-geo-maxmind-geolite2-country-db-filepath
and advanced-ads-geo-maxmind-geolite2-city-db-filepath
to your theme’s functions.php
. It won’t work if you embed only one of them. See an example of implementing the code above.
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
function my_advads_geo_dir( $dir ){
// this would save the files in /wp-content/uploads
return '';
}
add_filter( 'advanced-ads-geo-upload-dir', 'my_advads_geo_dir' );
Code language: PHP (php)
advanced-ads-group-ad-count
Manipulate the number of ads displayed for a group. Used by the Slider add-on.
advanced-ads-group-displayed-ad-count
Manipulate the displayed ad count on the ad groups page.
Parameters:
- integer $ad_count the amount of displayed ads object
- Advanced_Ads_Group $group the current ad group object
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-import-default-group-weight
By default, Advanced Ads uses a weight of 5 for ads that were added to groups when imported automatically. Use the filter to change this default value.
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 );
Code language: PHP (php)
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-privacy-output-attributes
Filter the data attributes and allow removing/adding attributes from the privacy container. All attributes will be prefixed with data-
on output.
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)!==""})';
}
Code language: PHP (php)
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-selling-upload-file-size
Change the allowed size for images uploaded on the ad setup page in Selling Ads. Default is 1048576
.
add_filter( 'advanced-ads-selling-upload-file-size', function(){
return 2000000;
} );
Code language: JavaScript (javascript)
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-ajax-dropin-path
Manipulates the path to the ajax-hander.php
file. Use together only with advanced-ads-tracking-ajax-dropin-url
filter.
advanced-ads-tracking-ajax-dropin-url
Defines the URL for the tracking drop-in file
/**
* Change the file path and URL from wp-content/ajax-handler.php to a new folder (aa-tracking) in the same directory.
**/
add_filter('advanced-ads-tracking-ajax-dropin-path', function() {
return WP_CONTENT_DIR . '/aa-tracking';
});
add_filter('advanced-ads-tracking-ajax-dropin-url', function() {
return content_url('/aa-tracking');
});
Code language: PHP (php)
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.
/**
* 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';
}
add_filter( 'advanced-ads-tracking-dbop-capability', 'advads_adjust_tracking_db_capability');
Code language: PHP (php)
advanced-ads-tracking-clickable-types
Filter the ad types that can use click tracking.
advanced-ads-tracking-GA-click
Change the event name for ad clicks registered by Google Analytics from advanced-ads-click
to a custom expression like Clicks
.
add_filter( 'advanced-ads-tracking-ga-click', function(){
return 'your-custom-event-name';
} );
Code language: JavaScript (javascript)
advanced-ads-tracking-GA-impression
Change the event name for ad impressions registered by Google Analytics from advanced-ads-impression
to a custom expression like Impressions
.
add_filter( 'advanced-ads-tracking-ga-impression', function(){
return 'your-custom-event-name';
} );
Code language: JavaScript (javascript)
advanced-ads-tracking-load-header-scripts
Set to false
to prevent Advanced Ads Tracking from enqueuing any script files. This will break features.
add_filter( 'advanced-ads-tracking-load-header-scripts', '__return_false', 20 );
Code language: JavaScript (javascript)
advanced-ads-tracking-redirect-url
Change the target URL when clicked on a tracking link.
advanced-ads-tracking-query-string
Attach attributes from the visited URL to the target link. See Inherit query parameters.
advanced-ads-update-placements
Runs when placements are saved.
advanced-ads-visitor-conditions
Add or change visitor conditions.