PHPackages                             automattic/ad-code-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. automattic/ad-code-manager

ActiveWordpress-plugin

automattic/ad-code-manager
==========================

Easy ad code management

0.8.0(4mo ago)118151GPL-2.0-or-laterPHPPHP &gt;=7.4CI passing

Since Mar 21Pushed 1mo ago119 watchersCompare

[ Source](https://github.com/Automattic/ad-code-manager)[ Packagist](https://packagist.org/packages/automattic/ad-code-manager)[ Docs](https://github.com/Automattic/ad-code-manager/)[ RSS](/packages/automattic-ad-code-manager/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (9)Used By (0)

Ad Code Manager
===============

[](#ad-code-manager)

Stable tag: 0.8.0
Requires at least: 6.4
Tested up to: 6.9
Requires PHP: 7.4
License: GPLv2 or later
License URI:
Tags: advertising, ad codes, ads, adsense, dfp, doubleclick for publishers
Contributors: rinatkhaziev, jeremyfelt, danielbachhuber, carldanley, zztimur, automattic, doejo, garyj

Manage your ad codes through the WordPress admin safely and easily.

Description
-----------

[](#description)

Ad Code Manager gives non-developers an interface in the WordPress admin for configuring your complex set of ad codes.

Some code-level configuration may be necessary to set up Ad Code Manager. Ad tags must be added (via `do_action()`) to your theme's template files where you'd like ads to appear. Alternatively, you can incorporate ad tags into your website with our widget and shortcode. Check out the configuration guide below for the full details.

A common set of parameters must also be defined for your ad provider. This includes the tag IDs used by your template, the default URL for your ad provider, and the default HTML surrounding that URL. Ad Code Manager supports Google DoubleClick For Publishers (and Async), and Google AdSense. All the logic is abstracted, however, so configuring a different provider is relatively easy. Check `providers/doubleclick-for-publishers.php` for an idea of how to extend ACM to suit your needs.

Once this configuration is in place, the Ad Code Manager admin interface will allow you to add new ad codes, modify the parameters for your script URL, and define conditionals to determine when the ad code appears. Conditionals are core WordPress functions like is\_page(), is\_category(), or your own custom functions that evaluate certain expressions and then return true or false.

[Fork the plugin on Github](https://github.com/Automattic/Ad-Code-Manager) and [follow our development blog](http://adcodemanager.wordpress.com/).

Installation
------------

[](#installation)

The plugin requires PHP 7.4 or later. It is also tested WordPress 6.4 and later, though it may run on older versions.

Since the plugin is in its early stages, there are a couple additional configuration steps:

1. Upload `ad-code-manager` to the `/wp-content/plugins/` directory.
2. Activate the plugin through the 'Plugins' menu in WordPress.
3. Incorporate ad tags in your theme template with `do_action( 'acm_tag', 'slot' );`. Also, you can use `[acm-tag id="slot"]` shortcode or ACM Widget.
4. Implement filters to make the plugin work with your provider.
5. Configure your ad codes in the WordPress admin (Tools -&gt; Ad Code Manager).

Screenshots
-----------

[](#screenshots)

1. Adding an ad code with a site name, zone, and multiple conditionals. [![Adding an ad code with a site name, zone, and multiple conditionals.](.wordpress-org/screenshot-1.png)](.wordpress-org/screenshot-1.png)
2. Edit existing ad codes inline through the admin interface. [![Edit existing ad codes inline through the admin interface.](.wordpress-org/screenshot-2.png)](.wordpress-org/screenshot-2.png)
3. Access the Help menu in the upper right for configuration assistance. [![Access the Help menu in the upper right for configuration assistance.](.wordpress-org/screenshot-3.png)](.wordpress-org/screenshot-3.png)
4. Example of ad tag in use in a theme header template. [![Example of ad tag in use in a theme header template.](.wordpress-org/screenshot-4.jpg)](.wordpress-org/screenshot-4.jpg)

Configure Ad Code Manager to manage the advertisements on your site
-------------------------------------------------------------------

[](#configure-ad-code-manager-to-manage-the-advertisements-on-your-site)

Ad Code Manager is a VIP-sponsored plugin designed to make managing the ad codes used to display advertisements on your site easier. There's a little bit of work you'll need to do upfront to integrate Ad Code Manager with your theme.

The high-level idea behind Ad Code Manager is that it gives non-developers an admin interface to manage ad codes. It then permits users to (optionally) target specific ad codes using conditionals like `is_home()` and `is_single()`. Ad codes are associated with positions in the theme through the use of ad tags.

Currently, Ad Code Manager easily integrates with Google DoubleClick For Publishers Async and Google AdSense. Other ad providers are supported with additional configuration.

### Google AdSense and DoubleClick For Publishers Async

[](#google-adsense-and-doubleclick-for-publishers-async)

Let's use AdSense as our first example. You'll want to incorporate some of the default ad tags into your theme by use of `do_action()`. Here's an example you might put in your header.php file:

```
do_action( 'acm_tag', '728x90_leaderboard' );
```

Once done, you can select the "Google AdSense" provider in the admin. Ad codes can be registered against ad tags (positions) by choosing the ad tag from the drop-down, entering the tag ID and publisher ID, and hitting "Add New Ad Code".

And like that, your 728x90 leaderboard will appear on your site.

The Google AdSense configuration comes with many of Google's suggested sizes. Additional ad tags can be registered by way of filtering:

```
add_filter( 'acm_ad_tag_ids', 'acmx_filter_ad_tag_ids' );
function acmx_filter_ad_tag_ids( $ids ) {
	$ids[] = array(
		'enable_ui_mapping' => true,
		'tag'               => '100x100_smallsquare',
		'url_vars'          => array(
			'tag'    => '100x100_smallsquare',
			'height' => '100',
			'width'  => '100',
		),
	);

	return $ids;
}
```

Keep in mind that you'll still need to incorporate a `do_action( 'acm_tag', '100x100_smallsquare' );` in your theme to display the ad tag.

If you choose Google DFP Async as your provider, you'll likely need to register additional ad tags, as we only package two default ad tags.

### Custom Ad Provider Implementations

[](#custom-ad-provider-implementations)

As mentioned previously, other ad code providers are supported with additional configuration. Here's an example of the different filters you would use to configure the older version of Google DoubleClick For Publishers:

```
/**
 * Define the default URL to be used when rendering ad codes
 */
add_filter( 'acm_default_url', 'acmx_filter_default_url' ) ;
function acmx_filter_default_url( $url ) {
	if ( 0 === strlen( $url )  ) {
		return "http://ad.doubleclick.net/adj/%site_name%/%zone1%;s1=%zone1%;s2=;pid=%permalink%;fold=%fold%;kw=;test=%test%;ltv=ad;pos=%pos%;dcopt=%dcopt%;tile=%tile%;sz=%sz%;";
	}
}

/**
 * Whitelist the DFP URL to be used in ad tags. The whitelist
 * helps prevent execution of arbitrary scripts
 */
add_filter( 'acm_whitelisted_script_urls', 'acmx_filter_whitelisted_script_urls');
function acmx_filter_whitelisted_script_urls( $whitelisted_urls ) {
	$whitelisted_urls = array( 'ad.doubleclick.net' );
	return $whitelisted_urls;
}

/**
 * Define the different ad tags (locations) you'd like to use in your theme
 */
add_filter( 'acm_ad_tag_ids', 'acmx_ad_tags_ids' );
function acmx_ad_tags_ids( $ad_tag_ids ) {
	return array(
		array(
			'tag'      => '728x90-atf',
			'url_vars' => array(
				'sz'     => '728x90',
				'fold'   => 'atf',
				'width'  => '728',
				'height' => '90',
			),
		),
		array(
			'tag'      => '728x90-btf',
			'url_vars' => array(
				'sz'     => '728x90',
				'fold'   => 'btf',
				'width'  => '728',
				'height' => '90',
			),
		),
		array(
			'tag'      => '300x250-atf',
			'url_vars' => array(
				'sz'     => '300x250',
				'fold'   => 'atf',
				'width'  => '300',
				'height' => '250',
			),
		),
		array(
			'tag'      => '300x250-btf',
			'url_vars' => array(
				'sz'     => '300x250',
				'fold'   => 'btf',
				'width'  => '300',
				'height' => '250',
			),
		),
		array(
			'tag'      => '160x600-atf',
			'url_vars' => array(
				'sz'     => '160x600',
				'fold'   => 'atf',
				'width'  => '160',
				'height' => '600',
			),
		),
		array(
			'tag'      => '1x1',
			'url_vars' => array(
				'sz'   => '1x1',
				'fold' => 'int',
				'pos'  => 'top',
			),
		)
	);
}

add_filter( 'acm_output_html','acmx_filter_output_html', 5, 2 );
/**
 * Register the full script output to use with each ad tag.
 */
function acmx_filter_output_html( $output_html, $tag_id ) {
	$output_html = '

if ( typeof ord=='undefined' ) { ord=Math.random()*10000000000000000; }
if ( typeof( dfp_tile ) == 'undefined' ) { dfp_tile=%tile% };
document.write('');
