Adding javascript script to header via functions.php


I’ve posted a very similar question to this in the past but I’m still having trouble and I have new updates.

This is my website ( and I’m trying to insert a Javascript widget into my header which is currently not working. I’m using the ‘Metro Magazine’ theme.

I’ve tried using the plugin ‘Header and Footer’ but it’d only add it to the footer, for the header it just wouldn’t work.

So I’ve went as far as opening the functions.php file for my theme and I’ve inserted the following code on the end:

function mytheme() {
  wp_register_script ('crypto', get_stylesheet_directory_uri() .      '/js/crypto.js', true);
  wp_enqueue_script ('crypto');

add_action( 'wp_enqueue_scripts', 'mytheme' );

And this is my script:

<script type="text/javascript">
baseUrl = "";
var scripts = document.getElementsByTagName("script");
var embedder = scripts[ scripts.length - 1 ];
(function (){
var appName = encodeURIComponent(window.location.hostname);
var s = document.createElement("script");
s.type = "text/javascript";
s.async = true;
var theUrl = baseUrl+'serve/v1/coin/header?   fsym=BTC&tsyms=USD,EUR,CNY,GBP';
s.src = theUrl + ( theUrl.indexOf("?") >= 0 ? "&" : "?") + "app=" +    appName;

Still nothing goes on, feels like there isn’t even anything happening! 🙁

Help would be extremely appreciated,

thank you!

, Luis Carvalho 3 years 2020-06-04T23:10:44-05:00 0 Answers 92 views 0

Leave an answer