can’t add 2 script or 2 short code
-
hey!
As the title says I’m trying to add 2 script using Elementor or using the WordPress editor but without success, only one of them is loading. I also tried to create 2 short codes that include the scrips but only 1 is loading on the page.
Would appreciate your help.
Thanks.
-
Show us the scripts and describe how you proceeded to integrate them.
This is the script i’m trying to add in two different parts of the same page:
‘`<html>
<head>
<title></title>
</head>
<body>
<h1></h1>
<p id=”btcIlsRate”></p><script>
let btcUsdtRate;
let exchangeRate;async function getBtcUsdtRate() {
const response = await fetch(‘https://api.binance.com/api/v1/ticker/price?symbol=BTCUSDT’);
const data = await response.json();
btcUsdtRate = data.price;
}async function getExchangeRate() {
const response = await fetch(‘https://sheets.googleapis.com/v4/spreadsheets/1pD2OvlZGyGcXIApHXmBZUE0IPTD_bhdG0d14GBNWrhc/values/D2:D2?key=AIzaSyDZz8u5FEoQ4PW7P_TCdx2EqDPVY_Uo9tM’);
const data = await response.json();
exchangeRate = data.values[0][0];
}function updateBtcIlsRate() {
document.getElementById(‘btcIlsRate’).innerHTML =${(btcUsdtRate * exchangeRate).toFixed(2)}
;
}async function getRates() {
await getBtcUsdtRate();
await getExchangeRate();
updateBtcIlsRate();
}setInterval(getRates, 1000);
</script>
</body>
</html>
`
and i tried using elementor’s html element to add it, i tried through the wordpress’s html element, also tried to use HFCM and Code Snippet addons to create short codes to the script and implement but it didn’t work. also i tried to combine using the html element on wordpress or elementor and using a shortcode but that didn’t work..-
This reply was modified 2 years, 3 months ago by
eyalnagar.
This is the script i’m trying to add in two different parts of the same page:
<html> <head> <title></title> </head> <body> <h1></h1> <p id=”btcIlsRate”></p> <script> let btcUsdtRate; let exchangeRate; async function getBtcUsdtRate() { const response = await fetch(‘https://api.binance.com/api/v1/ticker/price?symbol=BTCUSDT’); const data = await response.json(); btcUsdtRate = data.price; } async function getExchangeRate() { const response = await fetch(‘https://sheets.googleapis.com/v4/spreadsheets/1pD2OvlZGyGcXIApHXmBZUE0IPTD_bhdG0d14GBNWrhc/values/D2:D2?key=AIzaSyDZz8u5FEoQ4PW7P_TCdx2EqDPVY_Uo9tM’); const data = await response.json(); exchangeRate = data.values[0][0]; } function updateBtcIlsRate() { document.getElementById(‘btcIlsRate’).innerHTML = ${(btcUsdtRate * exchangeRate).toFixed(2)}; } async function getRates() { await getBtcUsdtRate(); await getExchangeRate(); updateBtcIlsRate(); } setInterval(getRates, 1000); </script> </body> </html>
and i tried using elementor’s html element to add it, i tried through the wordpress’s html element, also tried to use HFCM and Code Snippet addons to create short codes to the script and implement but it didn’t work. also i tried to combine using the html element on wordpress or elementor and using a shortcode but that didn’t work..
This is not just a script but a corrupted HTML code with a JavaScript in it as well. I suspect besides the unnecessary HTML elements, the incorrect spelling of the single and double quotes is also a problem.
With the following code I only get an error message:
<p id="btcIlsRate"></p> <script> let btcUsdtRate; let exchangeRate; async function getBtcUsdtRate() { const response = await fetch('https://api.binance.com/api/v1/ticker/price?symbol=BTCUSDT'); const data = await response.json(); btcUsdtRate = data.price; } async function getExchangeRate() { const response = await fetch('https://sheets.googleapis.com/v4/spreadsheets/1pD2OvlZGyGcXIApHXmBZUE0IPTD_bhdG0d14GBNWrhc/values/D2:D2?key=AIzaSyDZz8u5FEoQ4PW7P_TCdx2EqDPVY_Uo9tM'); const data = await response.json(); exchangeRate = data.values[0][0]; } function updateBtcIlsRate() { document.getElementById('btcIlsRate').innerHTML = ${(btcUsdtRate * exchangeRate).toFixed(2)}; } async function getRates() { await getBtcUsdtRate(); await getExchangeRate(); updateBtcIlsRate(); } setInterval(getRates, 1000); </script>
The error message refers to this line:
document.getElementById('btcIlsRate').innerHTML = ${(btcUsdtRate * exchangeRate).toFixed(2)};
This can’t work like this because the curly braces are not allowed here. Wherever you got this script from – you have to get it with correct notation.
So you suspect that because there’s issues with the script i can’t load 2 in the same page? because if i load just 1 it works perfectly.. i didn’t really understand what exactly needs to be fixed i am not a developer unfortunately i got the script from ChatGPT. Can you elaborate about what needs to be fixed it the script in order to load 2 or more of it on the same page?
I can’t even load a single script. If you want to run this twice, you have to rename all function names for the 2nd inclusion and use new IDs – or develop a really dynamic script. A bot can’t solve everything for you. If you need human support for this, you might find someone here: https://jobs.wordpress.net/
ok thanks!
-
This reply was modified 2 years, 3 months ago by
- The topic ‘can’t add 2 script or 2 short code’ is closed to new replies.