Support

Account

Home Forums General Issues add to ACF field

Solved

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(“&&#8221;));
    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(“&&#8221;)); 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.

  • You use a text field with no formatting on the return value.

  • 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.

  • shorcode worked, thanks ๐Ÿ™‚

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.