Configure Ad Code Manager to manage the advertisements on your site

Ad Code Manager is a VIP-sponsored plugin designed to make it easier to manage the ad codes used to display advertisements on your site. There’s a little bit of work you’ll need to do up front, however, in order to integrate Ad Code Manager with your theme.

Note: WordPress.com Enterprise users should contact support and we’ll take care of the configuration for you.

The high-level idea behind Ad Code Manager is that it gives non-developers an admin interface to manage your 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

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 you’ve done so, 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”.

Google AdSense configuration

And like that, your 728×90 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 the way of filtering:

add_filter( 'acm_ad_tag_ids', 'acmx_filter_ad_tag_ids' );
function acmx_filter_ad_tag_ids( $ids ) {

	$ids[] = array(
		'tag'       => '100x100_smallsquare',
		'url_vars'  => array(
			'tag'       => '100x100_smallsquare',
			'height'    => '100',
			'width'     => '100',
			),
		'enable_ui_mapping' => true,
	);

	return $ids;
}

Keep in mind that you’ll still need to incorporate a do_action( 'acm_tag', '100x100_smallsquare' ); in your theme in order 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

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:

<?php
/**
 * 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',
					)
			)
		);	
}

/**
 * Register the full <script> output to use with each ad tag
 */
add_filter( 'acm_output_html','acmx_filter_output_html', 5, 2 );
function acmx_filter_output_html( $output_html, $tag_id ) {
	$output_html = '<!-- DFP %pos% %sz% ad tag --> 
	<script language="JavaScript" type="text/javascript">
if (typeof ord=='undefined') {ord=Math.random()*10000000000000000;}
if (typeof(dfp_tile) == 'undefined') dfp_tile=%tile%;
document.write('<script language="JavaScript" src="%url%ord=' + ord + '?" type="text/javascript"></script>');
</script><noscript><a href="%url%ord=%random%?" target="_blank"><img src="%url%ord=%random%?" width="%width%" height="%height%" border="0" alt=""></a></noscript>
<!-- //DFP %pos% %sz% tag -->';
	return $output_html;
}

/**
 * Fine tune our output tokens
 * This is the real example of how easily you can modify output
 * depending on your ad network specs
 */
add_filter('acm_output_tokens', 'acmx_filter_output_tokens', 5, 3 );
function acmx_filter_output_tokens( $output_tokens, $tag_id, $code_to_display ) {
	global $dfp_tile;
	global $dfp_ord;
	global $dfp_pos;
	global $dfp_dcopt;
	global $wp_query;
	
	// We can't really rely on get_permalink() so use $_SERVER['REQUEST_URI] as bulletproof solution for generating unique pids
	$link = strlen( $_SERVER['REQUEST_URI'] ) > 1 ? sanitize_key( $_SERVER['REQUEST_URI'] ) : home_url();
	$output_tokens['%permalink%'] = str_replace( array( '/',':', '.' ), "", $link ); 
	$output_tokens['%random%'] = $dfp_ord;
	$output_tokens['%tile%'] = ++$dfp_tile;
	if (  false === $dfp_pos[ $code_to_display['url_vars']['sz'] ] ) {
		$output_tokens['%pos%'] = 'top';
		$dfp_pos[ $code_to_display['url_vars']['sz'] ] = true;
	} else {
		$output_tokens['%pos%'] = 'bottom';
	}
	if ( ! $dfp_dcopt ) {
		$output_tokens['%dcopt%'] = 'ist';
		$dfp_dcopt = true;
	} else {
		$output_tokens['%dcopt%'] = '';
	}
	
	$output_tokens['%test%'] = isset( $_GET['test'] ) && $_GET['test'] == 'on' ? 'on' : '';
	
	return $output_tokens;
}

Embedding rich media in your post

As a member of WordPress.com VIP, you are able to embed rich media into your posts. This document will quickly explain how embedding works.

Commonly Used Embeds

Looking to embed content from YouTube, Hulu, InstagramVimeoBlip.tvCNNMoney videoDaily MotionGist or Reddit? Simply copy the URL in your browser bar while viewing the video or photograph, and paste it into your editor on its own line. We’ll automatically embed the content for you.

Note: Make sure the URL is not linked or formatted in any way, and that it is on its own line. You can read more about WordPress’s custom embeds here.

Looking to embed content from Scribd, Slideshare, Wufoo, Flickr Video, SoundCloud or Bandcamp? Each of these services offers a WordPress.com shortcode that you can paste directly into your post editor. Click on the service’s name above for more information on how to embed their content.

Scripts, iFrames, and Objects

WordPress.com VIP handles embeds and scripts that haven’t already been whitelisted above in a special way for security protection. Here’s how to embed code that begins with `<script>, <iframe>, <object>`.

1) In your post editor, there is a tool above the formatting bar that allows you to include scripts. You can click either “Add Media” or “Add Embed.”

Screen Shot 2013-07-22 at 5.55.27 PM

2) A window will pop up. Be sure to select the “Insert Embed” tab. Paste the script code into this window, and click “Insert.”

Screen Shot 2013-07-22 at 5.55.56 PM

3) A shortcode will be inserted in your post, representing your protected embed.

Custom Widths/Heights For “Protected Embeds”

Our “protected embeds” feature attempts to make an educated guess at the ideal width or height of your embed, but if the object you’re embedding doesn’t make those values obvious, we’re not always able to do that. Instead, you can specify your own width or height attributes for the iframes in the shortcode, as such:

protected-iframe id="#" info="#" width="100%" height="200"

Importing Content with Embeds

If you’re importing content from a non-VIP site, you may have embedded scripts, iframes and objects that need to work on your WordPress.com VIP site. To ensure this happens, please open a support ticket and request that we handle the initial import for you, which will allow that embedded content to pass through the import process. Then, when you next edit one of those posts or pages, the embed will be automatically converted to a protected embed.

Allow Contributors to Upload Images

When images or other attachments are uploaded to a non-private WordPress site, the images are immediately public and can be shared on the Internet. This is why Contributors cannot normally upload images or files.

The VIP plugin repository file vip-helper-wpcom.php includes a helper function called vip_contrib_add_upload_cap() which will allow Contributors to upload. For Enterprise sites, there’s a plugin that can be activated from the admin called “Allow Contributors to Upload.”

Ready to get started?

Tell us about your needs

Let us lead the way. We’ll help you select a top tier development partner. We’ll train your developers, operations, infrastructure, and editorial teams. We’ll coarchitect your deployment processes. We will provide live support for peak events. We’ll help your people avoid dark alleys and blind corners, and reduce wasted cycles.