• Resolved Artan

    (@artankrasniqi1988)


    Hi there,

    I don′t know why, but my snippet is not working. When I insert it directly as HTML in the site, no problem. But through the plugin it won′t work. “Run snippet everywhere” is activated. And it′s also activated. It is shown in my console in <head> in front end. But why does it not trigger/work with plugin but without it when I insert it directly in my head template as HTML in a div / site builder? This is the snippet like it is inserted in the plugin:

    <?php
    add_action( 'wp_head', function () { ?>
    <script>
    
    document.getElementById("menu-item-136").addEventListener("mouseover", mouseOver);
    document.getElementById("menu-item-136").addEventListener("mouseout", mouseOut);
    
    function mouseOver() {
      document.getElementById("mega-menu").style.display = "block";
    }
    
    function mouseOut() {
      document.getElementById("mega-menu").style.display = "none";
    }
    
    </script>
    <?php } );

    Can u help please?

    Regards,

    Artan

    PS: Please inform me if u need login data, as the site is under construction. I could send u the data in private.

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Not an answer specific to your question — but this is my experience on this so far.

    Seems like all my snippets not loading properly now with WP 5.5.3 + BB Platform (some gets loaded, some are not) and its difficult to find out why. So I copied all snippets and move back to functions.php of my active theme, and deactivate those snippets in the snippet entries — which these, all is being loaded correctly.

    Plugin Author Shea Bunge

    (@bungeshea)

    @artankrasniqi1988 if the code is showing up exactly as expected in the site’s <head> section, then that indicates it’s an issue with the JavaScript code as opposed to this plugin.

    I have a feeling that it’s probably running before the page has had a chance to load properly. I’d recommend changing that wp_head action to wp_footer, or using a window.addEventListener('DOMContentLoaded', function () {}) wrapper.

    Thread Starter Artan

    (@artankrasniqi1988)

    Hi Shea,

    changing to wp_footer did the thing.

    Is there any difference in performance when not loaded in header? Or is there no difference. What is recommended? I use this for showing a mega menu when hovering over a menu button.

    Thank u very much for your support!

    Plugin Author Shea Bunge

    (@bungeshea)

    I believe that generally it’s best practice to load scripts in the footer area when it’s feasible to do so, as then they won’t block other parts of the page from loading. Especially seeing as this snippet does nothing on load and only responds to user interaction.

    Thread Starter Artan

    (@artankrasniqi1988)

    Well, thanks for the advice and the support!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Snippet not loading’ is closed to new replies.