{"id":14719117,"date":"2021-07-30T11:49:05","date_gmt":"2021-07-30T11:49:05","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/adding-code-in-section-not-working\/"},"modified":"2021-07-30T11:49:05","modified_gmt":"2021-07-30T11:49:05","slug":"adding-code-in-section-not-working","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/adding-code-in-section-not-working\/","title":{"rendered":"adding code in section not working"},"content":{"rendered":"<p>hello,<br \/>\nI&#8217;m trying to add some code in the &lt;head&gt; section of a website for tracking purposes, acting as specified <a href=\"https:\/\/amp-wp.org\/documentation\/playbooks\/classic-templates\/\">in documentation<\/a><\/p>\n<p>thus, i&#8217;ve added this code in the functions.php theme file:<\/p>\n<pre><code>\t&lt;script async src=&quot;https:\/\/cdn.ampproject.org\/v0.js&quot;&gt;&lt;\/script&gt;\n\t&lt;script async custom-element=&quot;amp-analytics&quot; src=&quot;https:\/\/cdn.ampproject.org\/v0\/amp-analytics-0.1.js&quot;&gt;&lt;\/script&gt;\n\t&lt;amp-analytics type=&quot;nielsen&quot;&gt;\n    &lt;script type=&quot;application\/json&quot;&gt;\n    {\n      &quot;vars&quot;: {\n        &quot;apid&quot;: &quot;F328C33C-5747-49C1-8F59-A396D28389B2&quot;,\n        &quot;prefix&quot;: &quot;eu-&quot;,\n        &quot;apv&quot;: &quot;1.0&quot;,\n        &quot;apn&quot;: &quot;FIRSTonline Website&quot;,\n        &quot;section&quot;: &quot;FIRSTonline_AMP&quot;,\n        &quot;segA&quot;: &quot;NA&quot;,\n        &quot;segB&quot;: &quot;NA&quot;,\n        &quot;segC&quot;: &quot;Google AMP&quot;\n      }\n    }\n    &lt;\/script&gt;\n&lt;\/amp-analytics&gt;\n<\/code><\/pre>\n<p>once done, looking at the resulting page, some parts of the code are filtered (the two &lt;script&gt; tags to include src files are missing) and the remaining code is postponed AFTER the closing &lt;\/head&gt; tag (which is not good for my desired result).<\/p>\n<p>It seems that something interferes reworking my code, but since no particular plugin is installed for such action, i&#8217;m wondering if i&#8217;m missing something or doing it completely wrong somehow&#8230;<\/p>\n<p>I&#8217;ve also tried with the amp subfolder in the theme folder approach (copying the plugins\/amp\/templates\/html-start.php file under the themes\/mytheme\/amp dir and editing it as needed with the code originally included in the functions.php file), obtaining more or less the same result.<\/p>\n<p>Eventually, can someone suggest some alternative way to directly add the code I need in the &lt;head&gt; section?<\/p>\n<p>plugin version is 2.1.3<br \/>\nwp version is 5.7.2<\/p>\n<p>thanks in advance for any help!<\/p>\n","protected":false},"template":"","class_list":["post-14719117","topic","type-topic","status-publish","hentry","topic-tag-head"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14719117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/14719117\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=14719117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}