內容簡介
DCO Insert Analytics Code 是一個 WordPress 外掛,旨在於在 </head> 之前、<body> 之後或 </body> 之前插入分析代碼(或任何自訂代碼)。
使用方法
在安裝和啟用後,您可以在外掛設置頁面的相應欄位中插入必要的代碼。
GitHub
設置
在 </head> 之前的代碼
在 <body> 之後的代碼
在 </body> 之前的代碼
過濾器列表
dco_iac_get_options
用於硬編碼覆蓋外掛設置的過濾器。使用此過濾器時,您將無法在設置頁面上編輯它們。
dco_iac_insert_before_head
用於更改代碼在 </head> 之前插入的過濾器。
dco_iac_insert_before_head_show
用於更改插入代碼在 </head> 之前顯示的過濾器。
dco_iac_insert_after_body
用於更改代碼在 <body> 之後插入的過濾器。
dco_iac_insert_after_body_show
用於更改插入代碼在 <body> 之後顯示的過濾器。
dco_iac_insert_before_body
用於更改代碼在 </body> 之前插入的過濾器。
dco_iac_insert_before_body_show
用於更改插入代碼在 </body> 之前顯示的過濾器。
dco_iac_disable_do_shortcode
用於禁用插入代碼中的短碼處理的過濾器。
過濾器使用示例
硬編碼覆蓋外掛設置
/*
* $current - 當前外掛設置
*
* $options - 來自數據庫的外掛設置
*
* $default - 默認外掛設置
*/
function custom_get_options($current, $options, $default) {
$array = array(
'before_head' => '<!-- before </head> -->',
'before_head_show' => '0',
'after_body' => '<!-- after <body> -->',
'after_body_show' => '1',
'before_body' => '<!-- before </body> -->',
'before_body_show' => '2'
);
return $array;
}
add_filter('dco_iac_get_options', 'custom_get_options', 10, 3);
更改在 </head> 之前的代碼
/*
* $code - 來自 "before </head>" 設置的值
*/
function custom_before_head_code( $code ) {
return $code . '<!-- before <head> -->' . "\n";
}
add_filter( 'dco_iac_insert_before_head', 'custom_before_head_code' );
更改在 </body> 之前的代碼顯示
/*
* $value - 來自 "before </body> show" 設置的值
*/
function custom_before_head_code( $value ) {
return '2';
}
add_filter( 'dco_iac_insert_before_body_show', 'custom_before_body_show' );
禁用插入代碼中的短碼處理
add_filter('dco_iac_disable_do_shortcode', '__return_true');
外掛標籤
開發者團隊
原文外掛簡介
DCO Insert Analytics Code is a WordPress plugin is intended for insert analytics code(or any custom code) before or after
or beforeUsage
After installation and activation, you can insert the necessary code to the respective fields on the plugin settings page.
GitHub
Settings
Before code
After
Before code
Filters list
dco_iac_get_options
Filter for hardcoding override plugin settings. You won’t be able to edit them on the settings page anymore when using this filter.
dco_iac_insert_before_head
Filter to change the code is inserted before
dco_iac_insert_before_head_show
Filter to change show the code is inserted before
dco_iac_insert_after_body
Filter to change the code is inserted after
dco_iac_insert_after_body_show
Filter to change show the code is inserted after
dco_iac_insert_before_body
Filter to change the code is inserted before
dco_iac_insert_before_body_show
Filter to change show the code is inserted before
dco_iac_disable_do_shortcode
Filter to disable shortcode processing in inserted codes
Examples of using filters
Hardcoding override plugin settings
/*
* $current - current plugin settings
*
* $options - plugin settings from database
*
* $default - default plugin settings
*/
function custom_get_options($current, $options, $default) {
$array = array(
'before_head' => '',
'before_head_show' => '0',
'after_body' => '',
'after_body_show' => '1',
'before_body' => '',
'before_body_show' => '2'
);
return $array;
}
add_filter('dco_iac_get_options', 'custom_get_options', 10, 3);
Change before code
/*
* $code - value from "before " setting
*/
function custom_before_head_code( $code ) {
return $code . '' . "\n";
}
add_filter( 'dco_iac_insert_before_head', 'custom_before_head_code' );
Change before
