Practically, you can access most functions and methods used in Advanced Ads, but there are some especially designed to be used in your frontend and theme files.
You can find these functions in advanced-ads/includes/functions.php .
advads_can_display_ads()
Returns false if ads are disabled on the current page view.
get_ad($id)
Get content of the ad with the ad id
Example:
<?php if(function_exists('get_ad')) echo get_ad($id); ?>
the_ad($id)
Echo the content of the ad with the ad id
Example:
<?php if(function_exists('the_ad')) the_ad($id); ?>
get_ad_group($id);
Get the content of an ad from an ad group using the ad group id.
Example:
<?php if(function_exists('get_ad_group')) echo get_ad_group($id); ?>
the_ad_group($id)
Echo the content of an ad from an ad group using the ad group id.
Example:
<?php if(function_exists('the_ad_group')) the_ad_group($id); ?>
get_ad_placement($id);
Get the content of an ad from an ad placement using the placement id.
Example:
<?php if(function_exists('get_ad_placement')) echo get_ad_placement($id); ?>
the_ad_placement($id)
Echo the content of an ad from an ad placement using the placement id.
Example:
<?php if(function_exists('the_ad_placement')) the_ad_placement($id); ?>
group_has_ads($id)
Check if the group with the given ID has any ads that can currently show up.
placement_has_ads($id)
Check if the placement with the given ID has any ads that can currently show up.
check if placement has ads using JavaScript
When ads are not loaded using PHP, but our JavaScript-based Cache Busting feature, you can use code like below to check if a placement is filled. This is just a mockup. Depending on when and where you load the code, you might use something like setInterval() to defer the check.
var placement_id = 'top'; // id of the placement, is derrived from the name var is_empty = true; if ( typeof advanced_ads_pro === 'object' ) { advanced_ads_pro.observers.add( function (event) { if ( event.event === 'inject_placement' && event.id === placement_id ) { is_empty = event.is_empty; // do whatever you want if ads are not loaded } } ); } jQuery(document).ready( alert( is_empty ) );
Additional attributes
You can use additional attributes when calling the functions to load an ad, group, or placement in order to override the options. This should be used by advanced developers only.
The attribute structure is derived from how options for ads, groups, or placements are stored. You should also notice the subarray change-ad, change-group, and change-placement depending on which level you would like to adjust.
The following example shows how to change the content of an ad and the top margin to 5 using $args in the get_ad function.
$args = array( 'change-ad' => array( 'content' => 'ad content', 'output' => array( 'margin' => array( 'top' => 5 ) ) ) ); get_ad( 123, $args );
You can also override options of the ads within a group or placement. The following changes the item displayed through the placement and the content of all ads displayed through them.
$args = array( 'change-placement' => array( 'item' => 'ad_211' ), 'change-ad' => array( 'content' => 'ad content', ) ); get_ad_placement( 'bc', $args );