Support » Plugin: Elementor Page Builder » How to add a javascript snippet to an Elementor page

  • Resolved mfeerer

    (@mfeerer)


    Hi. I am using Mailerlite for pop-up subscribe forms on my site. To activate an html link on my page that when clicked will show the pop-up form, Mailerlite instructs that I need to add a javascript snippet to my page…

    <script>
    var ml_webform_621928 = ml_account(‘webforms’, ‘921928’, ‘g6k8y6’, ‘load’);
    ml_webform_621928(‘animation’, ‘fadeIn’);
    </script>

    How do I do that in Elementor? Thanks.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 16 through 18 (of 18 total)
  • Den

    (@denmayday)

    I’ve had a similar issue but when js+css+html code was inserted into an html block it was working when I’m logged in as admin but for a normal visitor it was showing just a source js code for some reason which is frustrating. So I’ve installed Text Blocks plugin and copied my code in there and inserted only a shortcode of that block into Elementor an it worked.

    mesotu

    (@mesotu)

    Just my two cents here. You can inject the JS script on the page you need it to run by putting your JS in a block of code (below at bottom of this comment) and then putting in the post number.

    STEPS
    1) Make sure you’re using a child theme

    2) Put the code below in your functions.php file below everything else.

    3) Replace the number between the single quotation marks with the number of the page where it needs to work.

    Example: if (is_single (‘2791’)) {

    So instead of 2791, you put in, say, 156 if that’s the page number. If you’re a newbie, you’ll find this page number in the URL bar when you’re editing the page in question.

    If you want the JS to run everywhere, then put it between your <head> tags in your header.php file. You can copy the header.php file to your child theme and edit it there so you don’t lose the code on parent theme updates.

    4) Make sure to rename the function part at the top of the code. I just named it pop_up_box_javascript for demonstration purpose. Make sure this is changed at the top AND bottom of the code.

    5) Make sure you have your HTML on the Elementor page that is relevant to the JavaScript you want to run.

    Hope this helps. Good luck!

    /* You can put a comment here to help you remember what the code is for */

    function pop_up_box_javascript() {
    if (is_single (‘2791’)) {
    ?>

    <script type=”text/javascript”>

    /* YOUR JS CODE GOES here between the <script> tags */

    </script>

    <?php
    }
    }
    add_action(‘wp_head’, ‘pop_up_box_javascript’);

    • This reply was modified 1 month ago by  mesotu.

    Probababy the opposite of what you want to hear,,but..
    I had typewriter js effect with a cdn and it worked on inserting the code into a html section.

    Then on page refresh displayed all the text that was to be ‘type writed’
    i.e 7 lines of text instead of the effect type writing it.

    so i thought it wasnt working .
    i went to page review and the type writer effect was working fine….

    Isnt there a neater way of doing this in the production page, as my spacings are all out as i have 7 lines of code and not 1 in the page.

    • This reply was modified 2 weeks, 4 days ago by  babonday.
Viewing 3 replies - 16 through 18 (of 18 total)
  • You must be logged in to reply to this topic.