Surely.
function loadMenuScripts()
{
wp_enqueue_script( 'main', get_template_directory_uri() . 'js/main.js', array( 'jquery' ), '', false );
}
add_action( 'wp_enqueue_scripts', 'loadMenuScripts' );
Additionally, if you need to load it in the footer, go ahead and change the action to:
add_action( 'wp_footer', 'loadMenuScripts' );
Also, it seems as if this is an option for users.
Before enqueueing, check to see if your menu is being used:
if( class_exists( 'mega_menu` ) ) {
add_action( 'wp_footer', 'loadMenuScripts' ); // Or whatever.
}
So you don’t enqueue it if it’s not necessary.
In fact, I’d recommend you create a Class for this functionality and then decide, based on whether or not this Mega Menu is enabled, to enqueue its assets.
Related Posts:
- Merge two separate WP menus into one in Mobile view
- Twenty Fifteen: Change navigation menu behavior
- Cannot collapse a responsive menu in WordPress
- Add “onclick” option to header menu item
- Jquery dropdown menus working locally, but not in WordPress [duplicate]
- Add Javascript to WordPress Menu
- Adding a class (arrows) to main menu links that have children?
- jQuery Hoverintent plugin in TwentyEleven Menu [closed]
- Add class to menu ul with active child
- jQuery cookie not working properly in wordpress
- Create search form in menu as in Twenty Fourteen theme
- Hide menu item in certain condition
- Replace menu links with # and add name to its li
- I am facing a problem with the navigation menu of my website
- How to add fixed position in menu class for Twenty Twelve theme?
- Hierarchical menu nesting problem with jQuery targetting
- WordPress menu link not working
- Static page to one page- menu inactive items highlighted
- Add code to WordPress menu items by class
- superfish.js seems it is not working properly after wordpress upgarde to 4.6.1
- Adding numbers inside a span tag in nav menu [closed]
- Adding toggle-able element after menu item
- WordPress Menu adds an unwanted slash before anchor
- Drop Down menu expanded by default (on front page) [closed]
- WordPress Menus – How to add inline styles to UL menus
- WP Menu Rollover Nav Item and Effect DIV Elsewhere
- Menu item that hides when you click the previous submenu
- Event listener callback returns undefined element
- Mobile navigation javascript problem
- Add class to sub-menu from unrelated element
- Change hover to onclick on menu
- Homepage Menu Link Won’t Function
- How to create a mobile menu full screen overlay using Understraps Bootstrap 4 theme
- javascript i wrote not working, can’t figure out why [closed]
- how do you create this customize menu using wp_nav_menu function?
- Mobile menu not working – jQuery error?
- Walker or wp_get_nav_menu_items VS jQuery
- show a hidden ul if li is active
- How can I make menu items into two seperate buttons with different functions?
- Foundation Scripts not loading (custom theme)
- Links in new menu don’t work
- Menu Details Output in Javascript [closed]
- jQuery not working when used with wordpress menu
- Showing a link with Javascript based on log-in status
- How do i keep my current page menu highlighted on pagination?
- How do I get my nav menu to show sub pages?
- Add jQuery function to media button
- Changing when mobile menu is displayed
- Is it possible to animate the Twenty Eleven menu? [closed]
- How can I only show one responsive menu on mobile devices?
- Active Navigation Class Based on URL on icon
- javascript function wait until another function to finish
- Refresh/reload the content in Div using jquery/ajax
- Disable play/pause/full screen for HTML5
- How can I get form data with JavaScript/jQuery?
- Is there a way to enable Cross-Origin Resource Sharing for WordPress’ ajaxurl?
- How Does The Walker Class Work?
- Calling the Menu Title within wp_nav_menu array function
- How to hide an item from a menu to logged out users (without a plugin)
- Using ‘$’ instead of ‘jQuery’ in WordPress
- Large WP 3.0 menu times out and won’t save
- Terms with more than one occurrence have current-menu-item class in menu
- start_lvl on Walker is not working
- How to get Menu Navigation Labels to output HTML
- Benefits of using Nav Walker?
- has_children in custom nav_walker
- AJAX Contact Form Issue
- How to add wechat (weixin) link to navigation menu?
- Link that refers to a menu item with dynamically generated URL
- delete all post with certain meta_keys
- Menu jumping when calling it via PHP
- how to add custom wp_nav_menu class css selector to ul and a tags?
- Split into two seperate unordered lists with custom walker
- Call a javascript function from another file
- Adding an external link to wordpress menu
- Why is my array of nav menus returning empty?
- Can you exclude child pages of a specific parent within a navigation?
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- get_nva_menu_locations returns only filled ones
- wp_set_object_term via js btn frontend
- Add attributes to wrapper html generated by wp_nav_menu
- Get the link title attribute and send it google analytics as custom label via google tag manager using beehive pro for WordPress
- How can I click the parent menu then redirect to a special URL?
- Stuck while adding bootstrap navwalker class
- use value returned from shortcode as menu item
- Defer Parsing of Scripts
- Getting parent object_id of child menu items in WordPress menu
- How to remove a sub-menu using walker hooks/filters without relying on a custom walker?
- Calling wordpress menu outside ignores custom menu item
- Specific Page that convert Hyperlink to anchor in nav menu
- How can I make this custom design menu work in wordpress?
- Active menu item / category
- Add different span class to wp nav menu
- Help with changing style of the extended menu drop down [closed]
- How we show pages in dropdown
- wp_nav_menu doesn’t show on index page
- Add specific phrase after every product title including the discounted price? [closed]
- Ensure an external javascript file called from plugin is loaded after jquery is called
- Why my vertical tab js code is refreshing the page continuously? [closed]
- How to set menu Display location