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.
adsanity_ads_posts_columns #
Modifies the columns listed in the post listing on the admin.
[gist]19e7cabd26bfaff63b29f810fb7f2925[/gist]
adsanity_ads_sortable_posts_columns #
Modifies the list of sortable columns in the post listing on the admin.
[gist]a02c15897cb6fff31dc661da7560068d[/gist]
adsanity_ads_posts_columns_{$column}_value #
Allows you to set the value that should be displayed in a particular column. The column is identified by a key: {$column}
[gist]abe7418a645720bf2225dad9ee63b0b8[/gist]
adsanity_ad_sizes #
This filter allows you to change the ad sizes that are available to choose when creating an ad unit.
[gist]c906fc398ae5dc7479c1035a6dbf788c[/gist]
adsanity_ads_posts_sortable_by_{$orderby} #
Allows you to set custom sorting parameters
[gist]d560fa7012a535b4f845cb85880a1fb8[/gist]
pj_ads_labels #
Allows you to change the labels of the ads custom post type.
[gist]26eea2b3dbe4de33aa4b8fa4bfb281de[/gist]
ads_setup #
Allows you to modify any of the arguments passed to the register_post_type function
[gist]537464049cd25626fe636bea44ed3d17[/gist]
adsanity_post_class #
Allows you to modify the css classes that wrap an ad unit
[gist]470fb3a01fa9b74362f8dc78296d904c[/gist]
Actions #
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.
ads_init #
[gist]https://gist.github.com/brandondove/586daf3a0691a1ca03a45d8a9687819a[/gist]
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.
adsanity_before_ad_wrapper #
adsanity_before_ad #
adsanity_after_ad #
adsanity_after_ad_wrapper #
adsanity_before_track_click #
adsanity_before_redirect #
Ad Visibility #
All of our queries for ads use WP_Query
or 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-{size}
(example:ad-125x125
) – This allows you to style all ads of the same sizecolumn-{column number}
(example:column-2
) – While relevant only to groups of ads, this allows you to style all ads in a particular columnalignleft
|aligncenter
|alignright
|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.
Filters
Actions
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-125×125.php, where 125×125 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.
- adsanity_ads_posts_columns
- adsanity_ads_sortable_posts_columns
- adsanity_ads_posts_columns_{$column}_value
- adsanity_ad_sizes
- adsanity_ads_posts_sortable_by_{$orderby}
- pj_ads_labels
- ads_setup
- adsanity_post_class
- ads_init
- adsanity_before_ad_wrapper
- adsanity_before_ad
- adsanity_after_ad
- adsanity_after_ad_wrapper
- adsanity_before_track_click
- adsanity_before_redirect
Didn’t find what you were looking for?
If you’re a subscriber to AdSanity and don’t find an answer to your specific question please submit a request and our support department will address your issue quickly.