{"id":8135489,"date":"2016-09-04T09:23:09","date_gmt":"2016-09-04T09:23:09","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/javascript-in-header-2\/"},"modified":"2016-09-04T09:23:09","modified_gmt":"2016-09-04T09:23:09","slug":"javascript-in-header-2","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/javascript-in-header-2\/","title":{"rendered":"Javascript in Header"},"content":{"rendered":"<p>I&#8217;m trying to get a certain script to work.<br \/>\nIf i put line 1 and 2 manually in a header.php, it works.<br \/>\nNow, (in order to avoid having to edit header.php every time) i&#8217;m trying to put it into a plugin.<\/p>\n<p>1)<\/p>\n<pre><code>&lt;script src=&quot;https:\/\/extern.finnik.nl\/kentekenbox\/v1\/kb.js&quot; type=&quot;text\/javascript&quot;&gt;\n&lt;\/script&gt;<\/code><\/pre>\n<p>I can see this appearing in my header when i look at the source of a page when i use this:<\/p>\n<pre><code>function my_finnik_js() {\n    \necho &#039;&lt;script type=&quot;text\/javascript&quot; src=&quot;https:\/\/extern.finnik.nl\/kentekenbox\/v1\/kb.js&quot;&gt;&lt;\/script&gt;&#039;;\n\n}\n\n\/\/ Add hook for front-end &lt;head&gt;&lt;\/head&gt;\n\nadd_action(&#039;wp_head&#039;, &#039;my_finnik_js&#039;);<\/code><\/pre>\n<p>Now line 2)<br \/>\n2)<\/p>\n<pre><code>&lt;script type=&quot;text\/javascript&quot;&gt;\ninitFinnikKentekenbox(&#039;Het Automeisje&#039;, &#039;finnik-kentekenbox-container&#039;, 300, false);\n&lt;\/script&gt;<\/code><\/pre>\n<p>When i try to get this in the head also, with code below, it crashes my site.<\/p>\n<pre><code>function my_finnik2_js() {\n    \n&lt;?php wp_enqueue_script(&#039;custom&#039;, &#039;initFinnikKentekenbox(&#039;De leukste autosite van Nederland&#039;, &#039;finnik-kentekenbox-container&#039;, 300, false)&#039;); ?&gt;\n\n}\n\n\/\/ Add hook for front-end &lt;head&gt;&lt;\/head&gt;\n\nadd_action(&#039;wp_head&#039;, &#039;my_finnik2_js&#039;);<\/code><\/pre>\n<p>I&#8217;m an absolute beginner in this and i hope someone can tell me why it doesn&#8217;t work, or rather how it WILL work.<br \/>\nThanks in advance, Marco<\/p>\n","protected":false},"template":"","class_list":["post-8135489","topic","type-topic","status-publish","hentry","topic-tag-header","topic-tag-javasript","topic-tag-wp_enqueue","topic-tag-wp_head"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8135489","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\/8135489\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=8135489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}