Here i am trying to add a google tag manager script on wordpress backend edit.php screen but whenever i add a script it gives error in console.
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.
Here is the code for the same
$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'
);
}
please help me how can i fix this issue in my custom plugin
2
Answers
You’re going to want to use
admin_enqueue_scripts
.Something along the lines of:
Use the
admin_head
hook in functions.php file of your theme-Replace the script from to with your GTM script.