在这里,我尝试在 WordPress 后端 edit.php 屏幕上添加谷歌标签管理器脚本,但每当我添加脚本时,它都会在控制台中出现错误。
Refused to load the script 'https://www.googletagmanager.com/gtag/js?id=[TAG-ID]&ver=1.0.0' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
这是相同的代码
$func_page = array("edit","post","edit-tags");
if(in_array($current_page, $func_page, true)) {
wp_enqueue_script(
'google-analytics',
'https://www.googletagmanager.com/gtag/js?id=[TAG-ID]',
array(),
'1.0.0'
);
}
请帮助我如何在我的自定义插件中解决这个问题
admin_enqueue_scripts
。
大致如下:
function add_gtag_to_admin() {
wp_enqueue_script(
'google-analytics',
'https://www.googletagmanager.com/gtag/js?id=[TAG-ID]',
array(),
'1.0.0'
);
}
add_action( 'admin_enqueue_scripts', 'add_gtag_to_admin' );