Home › Forums › General Issues › add to ACF field
how can i add a script like this as a field in ACF? i want to embed a windguru graph into my listing
<script id=”wg_fwdg_273_100_1684893890744″>
(function (window, document) {
var loader = function () {
var arg = [“s=273″ ,”m=100″,”uid=wg_fwdg_273_100_1684893890744″ ,”wj=knots” ,”tj=c” ,”waj=m” ,”odh=0″ ,”doh=24″ ,”fhours=240″ ,”hrsm=2″ ,”vt=forecasts” ,”lng=en” ,”idbs=1″ ,”p=WINDSPD,GUST,SMER,TMPE,FLHGT,CDC,APCP1s,RATING”];
var script = document.createElement(“script”);
var tag = document.getElementsByTagName(“script”)[0];
script.src = “https://www.windguru.cz/js/widget.php?”+(arg.join(“&”));
tag.parentNode.insertBefore(script, tag);
};
window.addEventListener ? window.addEventListener(“load”, loader, false) : window.attachEvent(“onload”, loader);
})(window, document);
</script>
If the script is the same every time. You could add it to the code for the page and wrap it in an IF statement. Use a true false field to turn it on an off..
The code would be
<?php if(get_field(‘field_name’):?>
…copy script here
<?php endif;?>
If you want to manually add different scripts then make a TextArea field and input it into that.
it displays on the front end as
(function (window, document) { var loader = function () { var arg = [“s=273″ ,”m=100″,”uid=wg_fwdg_273_100_1684893432104″ ,”wj=knots” ,”tj=c” ,”waj=m” ,”odh=0″ ,”doh=24″ ,”fhours=240″ ,”hrsm=2″ ,”vt=fcst_graph” ,”lng=en” ,”idbs=1″ ,”p=”]; var script = document.createElement(“script”); var tag = document.getElementsByTagName(“script”)[0]; script.src = “https://www.windguru.cz/js/widget.php?”+(arg.join(“&”)); tag.parentNode.insertBefore(script, tag); }; window.addEventListener ? window.addEventListener(“load”, loader, false) : window.attachEvent(“onload”, loader); })(window, document);
i am using divi and it seems the dynamic text module is placing the code into the visual editor.
i am usinh a text field. i think the divi dynamic content is automatically put into the visual text editor with no way to specify it is not 🙁
You need to figure out if Divi has a way to disable whatever is being done. It is obviously passing the content though WP filters. You might try using the ACF shortcode.
If that does not work then you’ll need help from Divi or someone that know how to get around this in Divi.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.