We have built some custom filters into AdSanity to help developers like yourself extend and/or modify the default behaviors. Below is a list of filters that we include in the plugin. Custom code can be placed in your theme's functions.php file or in a custom plugin.
Modifies the columns listed in the post listing on the admin.
Modifies the list of sortable columns in the post listing on the admin.
Allows you to set the value that should be displayed in a particular column. The column is identified by a key:
This filter allows you to change the ad sizes that are available to choose when creating an ad unit.
Allows you to set custom sorting parameters
Allows you to change the labels of the ads custom post type.
Allows you to modify any of the arguments passed to the register_post_type function
Allows you to modify the css classes that wrap an ad unit
We have built some custom actions into AdSanity to help developers like yourself extend the default behaviors. Below is a list of actions that we include in the plugin. Custom code can be placed in your theme’s functions.php file or in a custom plugin.
the ads_init function runs when the ads post type is being set up. You could use this hook to register additional taxonomies for example.
Ad Visibility #
All of our queries for ads use
get_posts(), so you are able to use WordPress core hooks like
pre_get_post as well as the hooks listed below.
Random Ad/Ad Group #
apply_filters( 'adsanity_hide_ad_group', $group_ids ); - Needs to return an array. $group_ids is an array of Ad Group IDs that you want included in the ad display. All ads in the included groups will be eligible for display. This is populated from the selections made in a widget, shortcode attributes, block, or template tag.
apply_filters( 'adsanity_hide_ad_in_group', array(), $group_ids ); - Needs to return an array. The array is empty by default, but you can add specific Ad Post IDs to be excluded from display. These ads would be intentionally not included in the display even if they are in the Ad Groups from the above filter.
Single Ad #
apply_filters( 'adsanity_hide_ad', false, $post_id ); - Needs to return a boolean. If true, the ad will not display. The boolean is false by default.
Customizing Ad Display #
One of the things we get asked about a lot is how to avoid detection from Ad Blockers. While we've explained other options to respect those visitor's ad display preferences, we understand that there are some instances that you aren't using AdSanity for typical advertising. Maybe you're just using AdSanity to track views and clicks on Image based content, for example. We provide you with a couple of methods to modify the display of individual ads, groups of ads, or all ads.
Styling Ad Units #
Each Ad Unit has a number of CSS Classes and a unique HTML ID that you can target in your theme's CSS to change its look. The format of these are:
ad-125x125) - This allows you to style all ads of the same size
column-2) - While relevant only to groups of ads, this allows you to style all ads in a particular column
alignnone- These four styles are generally already handled inside of most themes, but if you want to apply additional styles to better handle alignment, this is the place to do so. Note: only one class will be added to each ad unit.
If all of those classes don't suit your needs or you want to change them, you can attach additional classes to each Ad Unit using a filter as described below.
Display Related Hooks #
There are a few display related actions and filters built into our templating system. These allow you to filter CSS classes and add markup around the ad unit so that you can style it.
Theme Templates #
Sometimes you need to have more control over the markup for your ads. We've extended WordPress Core's template hierarchy to allow you to fully customize an ad's markup through a theme template.
If you want to change the markup of all ads, simply copy the
ad.php file from the
theme-templates folder into your theme and customize away.
If you want to modify the markup for all ads of a particular size, you can rename that file to something like ad-125x125.php, where 125x125 is the size that you're trying to modify. Note: you can find the size by looking at the classes that are applied to the ad in the markup.
Finally, if you want to change the markup of one particular ad, you can rename the file to ad-1234.php where 1234 is the ID of the ad you want to modify. Note: you can find the ID by looking at the HTML ID that is applied to the ad in the markup.