Title: Snippet not loading
Last modified: November 26, 2020

---

# Snippet not loading

 *  Resolved [Artan](https://wordpress.org/support/users/artankrasniqi1988/)
 * (@artankrasniqi1988)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/snippet-not-loading/)
 * 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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fsnippet-not-loading%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [af3](https://wordpress.org/support/users/af3/)
 * (@af3)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/snippet-not-loading/#post-13725415)
 * 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](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/snippet-not-loading/#post-13725526)
 * [@artankrasniqi1988](https://wordpress.org/support/users/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](https://wordpress.org/support/users/artankrasniqi1988/)
 * (@artankrasniqi1988)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/snippet-not-loading/#post-13737032)
 * 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](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/snippet-not-loading/#post-13739871)
 * 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](https://wordpress.org/support/users/artankrasniqi1988/)
 * (@artankrasniqi1988)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/snippet-not-loading/#post-13759264)
 * 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.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

## Tags

 * [not-loading](https://wordpress.org/support/topic-tag/not-loading/)
 * [snippet](https://wordpress.org/support/topic-tag/snippet/)

 * 5 replies
 * 3 participants
 * Last reply from: [Artan](https://wordpress.org/support/users/artankrasniqi1988/)
 * Last activity: [5 years, 5 months ago](https://wordpress.org/support/topic/snippet-not-loading/#post-13759264)
 * Status: resolved