[WordPress] 外掛分享: Ad Code Manager

WordPress 外掛 Ad Code Manager 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「Ad Code Manager」是 2012-02-09 上架。
  • 目前有 70 個安裝啟用數。
  • 上一次更新是 2023-09-09,距離現在已有 603 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 5.7 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 7.4 以上。
  • 尚未有人給過這款外掛評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

doejo | zztimur | automattic | carldanley | jeremyfelt | rinatkhaziev | danielbachhuber |

外掛標籤

ads | dfp | adsense | ad codes | advertising |

內容簡介

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 = '
');

There are some filters which allow you to easily customize the output of the plugin. You should place these filters in your theme's functions.php file or in another appropriate place.

[Check out this gist](https://gist.github.com/1631131) to see all of the filters in action.

### `acm_ad_tag_ids`

Ad tag IDs are used as a parameter when adding tags to your theme (e.g. `do_action( 'acm_tag', 'my_top_leaderboard' )`). The `url_vars` defined as part of each tag here will also be used to replace tokens in your default URL.

Arguments:
* array $tag_ids array of default tag IDs

Example usage: Add a new ad tag called 'my_top_leaderboard'

~~~php
add_filter( 'acm_ad_tag_ids', 'my_acm_ad_tag_ids' );
function my_acm_ad_tag_ids( $tag_ids ) {
$tag_ids[] = array(
'tag' => 'my_top_leaderboard', // tag_id
'url_vars' => array(
'sz' => '728x90', // %sz% token
'fold' => 'atf', // %fold% token
'my_custom_token' => 'something' // %my_custom_token% will be replaced with 'something'
),
);
return $tag_ids;
}

acm_default_url
Set the default tokenized URL used when displaying your ad tags. This filter is required.
Arguments:
* string $url The tokenized URL of Ad Code
Example usage: Set your default ad code URL
add_filter( 'acm_default_url', 'my_acm_default_url' );
function my_acm_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%;";
}
}

acm_output_html
The HTML outputted by the do_action( 'acm_tag', 'ad_tag_id' ); call in your theme. Support multiple ad formats (e.g. JavaScript or simple HTML tags) by adjusting the HTML rendered for a given ad tag.
The %url% token used in this HTML will be filled in with the URL defined with acm_default_url.
Arguments:
* string $output_html The original output HTML
* string $tag_id Ad tag currently being accessed
Example usage:
add_filter( 'acm_output_html', 'my_acm_output_html', 10, 2 );
function my_acm_output_html( $output_html, $tag_id ) {
switch ( $tag_id ) {
case 'my_leaderboard':
$output_html = '
';
break;
case 'rich_media_leaderboard':
$output_html = '';
break;
default:
break;
}
return $output_html;
}

acm_register_provider_slug
Ad Code Manager has a built-in list of providers that it gathers by scanning the ‘providers’ directory used by the plugin. Additional providers can be added by placing the appropriate files in that directory or using the acm_register_provider_slug filter to register those that may be included as part of your theme or another plugin.
When using this plugin, you are defining the provider slug as part of the existing object as well as an array of classes associated with that provider slug.
Arguments:
* object $providers An object containing the current registered providers.
Example usage:
add_filter( 'acm_register_provider_slug', 'my_acm_register_provider_slug' );
function my_acm_register_provider_slug( $providers ) {
$providers->new_provider_slug = array(
'provider' => 'My_New_Ad_Company_ACM_Provider',
'table' => 'My_New_Ad_Company_ACM_WP_List_Table'
);

return $providers;
}

acm_whitelisted_script_urls
A security filter to define a safelist for which ad code script URLs can be added in the admin.
Arguments:
* array $whitelisted_urls Existing whitelisted ad code URLs
Example usage: Allow DoubleClick for Publishers ad codes to be used
add_filter( 'acm_whitelisted_script_urls', 'my_acm_safelisted_script_urls' );
function my_acm_safelisted_script_urls( $safelisted_urls ) {
$safelisted_urls = array( 'ad.doubleclick.net' );
return $safelisted_urls;
}

acm_output_tokens
Output tokens can be registered depending on the needs of your setup. Tokens defined here will be replaced in the ad tag’s tokenized URL in addition to the tokens already registered with your tag ID.
Arguments:
* array $output_tokens Any existing output tokens
* string $tag_id Unique tag ID
* array $code_to_display Ad Code that matched conditionals
Example usage: Test to determine whether you’re in test or production by passing ?test=on query argument
add_filter( 'acm_output_tokens', 'my_acm_output_tokens', 10, 3 );
function my_acm_output_tokens( $output_tokens, $tag_id, $code_to_display ) {
$output_tokens['%test%'] = isset( $_GET['test'] ) && $_GET['test'] == 'on' ? 'on' : '';
return $output_tokens;
}

acm_whitelisted_conditionals
Extend the list of usable conditional functions with your own awesome ones. We safelist these so users can’t execute random PHP functions.
Arguments:
* array $conditionals Default conditionals
Example usage: Register a few custom conditional callbacks
add_filter( 'acm_whitelisted_conditionals', 'my_acm_safelisted_conditionals' );
function my_acm_safelisted_conditionals( $conditionals ) {
$conditionals[] = 'my_is_post_type';
$conditionals[] = 'is_post_type_archive';
$conditionals[] = 'my_page_is_child_of';

return $conditionals;
}

acm_conditional_args
For certain conditionals (has_tag(), has_category()), you might need to pass additional arguments.
Arguments:
* array $cond_args Existing conditional arguments
* string $cond_func Conditional function (is_category(), is_page(), etc.)
Example usage: has_category() and has_tag() use has_term(), which requires the object ID to function properly.
add_filter( 'acm_conditional_args', 'my_acm_conditional_args', 10, 2 );
function my_acm_conditional_args( $cond_args, $cond_func ) {
global $wp_query;

// The `has_category()` and `has_tag()` functions call the `has_term()` function.
// We should pass queried object id for it to produce correct result.
if ( in_array( $cond_func, array( 'has_category', 'has_tag' ) ) && $wp_query->is_single == true ) {
$cond_args[] = $wp_query->queried_object->ID;
}

// my_page_is_child_of is our custom WP conditional tag and we have to pass queried object ID to it.
if ( in_array( $cond_func, array( 'my_page_is_child_of' ) ) && $wp_query->is_page ) {
$cond_args[] = $cond_args[] = $wp_query->queried_object->ID;
}

return $cond_args;
}

acm_display_ad_codes_without_conditionals
Change the behavior of Ad Code Manager so that ad codes without conditionals display on the front end. The default behavior is that each ad code requires a conditional to be included in the presentation logic.
Arguments:
* bool $behavior Whether or not to display the ad codes that don’t have conditionals
Example usage:
add_filter( 'acm_display_ad_codes_without_conditionals', '__return_true' );

acm_provider_slug
By default, we use our bundled doubleclick_for_publishers config (check it in /providers/doubleclick-for-publishers.php). If you want to add your own flavor of DFP or even implement configuration for another ad network, you’d have to apply a filter to correct the slug.
Example usage:
add_filter(
'acm_provider_slug',
function() {
return 'my-ad-network-slug';
}
);

acm_logical_operator
By default, the logical operator is set to “OR”, that is, ad code will be displayed if at least one conditional returns true.
You can change it to “AND”, so that the ad code will be displayed only if ALL the conditionals match.
Example usage:
add_filter(
'acm_logical_operator',
function() {
return 'AND';
}
);

acm_manage_ads_cap
By default, the user has to have manage_options cap. This filter comes in handy if you want to relax the requirements.
Example usage:
add_filter(
'acm_manage_ads_cap',
function( $cap ) {
return 'edit_others_posts';
}
);

acm_allowed_get_posts_args
This filter is only for edge cases. Most likely, you won’t have to touch it. Allows to include additional query args for Ad_Code_Manager->get_ad_codes() method.
Example usage:
add_filter(
'acm_allowed_get_posts_args',
function( $args_array ) {
return array( 'offset', 'exclude' );
}
);

acm_ad_code_count
By default, the total number of ad codes to get is 50, which is reasonable for any small to mid-sized site. However, in certain cases, you would want to increase the limit. This will affect Ad_Code_Manager->get_ad_codes() numberposts query argument.
Example usage:
add_filter(
'acm_ad_code_count',
function( $total ) {
return 100;
}
);

acm_list_table_columns
This filter can alter table columns that are displayed in ACM UI.
Example usage:
add_filter( 'acm_list_table_columns', 'my_acm_list_table_columns' );
function my_acm_list_table_columns( $columns ) {
$columns = array(
'id' => __( 'ID', 'ad-code-manager' ),
'name' => __( 'Name', 'ad-code-manager' ),
'priority' => __( 'Priority', 'ad-code-manager' ),
'conditionals' => __( 'Conditionals', 'ad-code-manager' ),
);

return $columns;
}

acm_ad_code_args
This filter comes in pair with the previous one. It should return an array of ad network-specific parameters. E.g. in acm_list_table_columns example, we have ‘id’, ‘name’, ‘priority’, and ‘conditionals’. All of them except ‘name’ are generic for Ad Code Manager. Hence, acm_provider_columns should return only “name”.
“editable” and “required” indicate whether this field should be editable and required.
Example usage:
add_filter( 'acm_ad_code_args', 'my_acm_ad_code_args' );
function my_acm_ad_code_args( $args ) {
$args = array(
array(
'key' => 'name',
'label' => __( 'Name', 'ad-code-manager' ),
'editable' => true,
'required' => true,
),
);

return $args;
}

Change Log
View the change log.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Ad Code Manager」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


0.2 | 0.3 | 0.4 | 0.5 | 0.1.2 | 0.1.3 | 0.2.1 | 0.2.2 | 0.2.3 | 0.4.1 | 0.6.0 | 0.7.1 | trunk |

延伸相關外掛(你可能也想知道)

  • Google for WooCommerce 》, Google Listings & Ads可讓您輕鬆地向Google平台上的購物者展示您的產品。無論您是數位廣告的新手還是市場營銷專家,您都可以通過免費和廣告來擴大您的...。
  • Facebook for WooCommerce 》這是官方版的「Facebook for WooCommerce」外掛,可將你的 WooCommerce 網站與 Facebook 連接。藉由此外掛,你可以安裝 Facebook 的像素碼、上傳你的線上商店...。
  • Head, Footer and Post Injections 》關於 WordPress SEO 和 Facebook Open Graph:我對 Yoast 的邀請讓我刪除我的外掛非常不滿,但實際上並不需要。, 點擊此處了解更多。, 頁首和頁尾代碼, 為什...。
  • Ad Inserter – Ad Manager & AdSense Ads 》這是一款廣告管理外掛程式,具有多種進階廣告功能,可在最佳位置插入廣告代碼。, 支援各種廣告,包括 Google AdSense、 Google Ad Manager (DFP - DoubleClic...。
  • Fixed Widget and Sticky Elements for WordPress 》使用 Fixed Widget 外掛可以創建黏貼式的小部件、區塊和其他元素,當用戶向上或向下滾動頁面時,它們會保持在可見的屏幕區域內。, 相較於非固定小工具,黏貼...。
  • Advanced Ads – Ad Manager & AdSense 》你正在尋找一款簡單的廣告管理外掛嗎?以下是使用 Advanced Ads 的主要理由:, , 自 2009 年以來經過審核,可優化發布和廣告, 適用於所有廣告類型和網絡,包...。
  • Ads.txt Manager 》這個 WordPress 外掛可以讓你在 WordPress 內創建、管理和驗證你的 ads.txt 和 app-ads.txt,就像管理任何其他內容資源一樣。需要 PHP 7.4+ 和 WordPress 5.7...。
  • Ads by WPQuads – Adsense Ads, Banner Ads, Popup Ads 》:, 傳說中的 WPQuads Ads 外掛程式現已以現代方法回歸提供廣告解決方案。WP QUADS 經過精簡編碼,不會造成過度負擔,被大型網站使用,每月的頁面點擊率達到...。
  • AdRotate Banner Manager – The only ad manager you'll need 》你是否在尋找易於使用的WordPress廣告管理外掛?以下是AdRotate Banner Manager可以為您做的事情:, , - 支援每一種廣告,包括亞馬遜廣告、聯盟網絡、Google ...。
  • Hide SEO Bloat 》這個外掛可以隱藏 Yoast SEO 的側邊欄廣告和高級版本按鈕,不管是設置頁面還是前台與後台的儀表板都適用。, Hide SEO Bloat 外掛的第一個版本在2015年4月發布...。
  • Meks Easy Ads Widget 》使用此 WordPress 外掛,您可以在 WordPress widget 中創建無限數量的廣告。提供了多個智能選項,以滿足您的廣告定製需求。, 特色, , 在一個 widget 中創建無...。
  • Insert Post Ads 》具有自動廣告注入的廣告外掛, 需要一種簡單的方法來自動插入文章廣告嗎?, 文章中的廣告點擊率最高。如果您想增加點擊率和 Google AdSense 收入,那麼您需要...。
  • Ezoic 》Ezoic外掛可提供WordPress網站需要的Ezoic功能和設定,包括:, , 自動插入Ezoic廣告佔位符, Ezoic Leap包含的網站性能優化, Ezoic快取和CDN設定, 檢測衝突的...。
  • In-feed ads for Google AdSense 》這個外掛是Advanced Ads廣告管理外掛的附加套件,它在首頁、分類頁面、標籤頁面或其他存檔頁面中的文章列表之間增加了Google AdSense In-feed廣告的放置位置...。
  • Monetag Official Plugin 》Monetag 是一個平台,用於支援桌面、手機網頁和應用程式的網路廣告庫存、社交流量,以及接觸世界各地廣告主進行營利。在 Monetag 上,我們提供多個高收益的工...。

文章
Filter
Apply Filters
Mastodon