
內容簡介
Ad Code Manager 提供 WordPress 管理介面,讓非開發者可以設定複雜廣告程式碼的配置。
設定 Ad Code Manager 可能需要一些程式碼上的配置。廣告標籤必須透過 do_action() 加入到您的主題模板檔程式碼中,並且要選擇要顯示廣告的位置。或者,您也可以透過我們的小工具及短碼將廣告標籤加入到您的網站中。詳細配置指南可參考下面的連結。
同時也需要定義廣告商家的許多參數,包括您的主題使用的標籤 ID、廣告商家的預設 URL,以及用於裝飾這個 URL 的預設 HTML。Ad Code Manager 支援 Google DoubleClick For Publishers(以及 Async)和 Google AdSense。不過整個架構都相當抽象化,所以配置其他廣告商家也相對容易。您可以查看 providers/doubleclick-for-publishers.php 取得延伸 ACM 的想法。
設定完成後,Ad Code Manager 的管理介面可以讓您新增廣告程式碼,在參數中修改您的腳本 URL,並定義在何時顯示該廣告程式碼。條件判斷可透過 WordPress 核心函式如 is_page()、is_category() 或您自己撰寫的自訂函式來評估特定的表達式,並回傳 true 或 false。
請到 GitHub 上複製外掛,或到 開發部落格 追蹤我們的最新消息。
配置 Ad Code Manager 管理您網站上的廣告
Ad Code Manager 是由 VIP 站贊助的外掛,旨在協助網站管理員更輕鬆地管理用於顯示廣告的廣告程式碼。不過,首先您需要花一些時間將 Ad Code Manager 整合到您的主題中。
Ad Code Manager 的核心概念是提供非開發者的管理介面,讓他們可以管理您的廣告程式檔案,並讓使用者可以選擇使用條件來選擇特定的廣告程式檔案,例如 is_home() 或 is_single()。廣告程式檔案是透過廣告標籤與主題中的位置相對應的。
目前 Ad Code Manager 直接整合了 Google DoubleClick For Publishers Async 和 Google AdSense,但其他廣告商家也可以透過進一步的設定來支援。
Google AdSense 和 DoubleClick For Publishers Async
首先,讓我們以 AdSense 為例。您可以在 header.php 檔案中使用一些預設的廣告標籤,藉由 do_action() 的方式加以引入。以下是您可能會使用的範例:
do_action( 'acm_tag', '728x90_leaderboard' );
完成後,您就可以在管理介面選擇使用「Google AdSense」的廣告商家。然後,透過下拉選單選擇對應的廣告標籤(位置),輸入標籤 ID 和廣告商家 ID,並點選「新增廣告程式檔案」。
只需要這樣,您的 728 × 90 美工版就會出現在網頁上了。
Google AdSense 的配置內含許多 Google 建議的廣告尺寸,而其他廣告標籤可以透過篩選的方式來加以註冊:
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;
}
K
外掛標籤
開發者團隊
原文外掛簡介
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 and follow our development blog.
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
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 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 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
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 = '
');
