Advanced

Filters

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.


# adsanity_ads_sortable_posts_columns

Modifies the list of sortable columns in the post listing on the admin.


# 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}


# adsanity_ad_sizes

This filter allows you to change the ad sizes that are available to choose when creating an ad unit.


# adsanity_ads_posts_sortable_by_{$orderby}

Allows you to set custom sorting parameters


# pj_ads_labels

Allows you to change the labels of the ads custom post type.


# ads_setup

Allows you to modify any of the arguments passed to the register_post_type function


# adsanity_post_class

Allows you to modify the css classes that wrap an ad unit

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:

  1. ad-{size} (example: ad-125x125) - This allows you to style all ads of the same size
  2. column-{column number} (example: column-2) - While relevant only to groups of ads, this allows you to style all ads in a particular column
  3. alignleft | 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-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.

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

https://gist.github.com/brandondove/586daf3a0691a1ca03a45d8a9687819a

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