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
- Override theme hamburger menu to work without javascript (noscript)
- How to add toggle-able DOM element after nav menu item?
- Where is my menu editor
- Hide menu items if the page content is empty
- Get custom classes in WordPress Navigation Menu
- WordPress Menu Exchange On Tablet’s Orientation
- JQuery Plugins in WordPress
- wp_nav_menu not displaying the right way
- Create special WordPress slideshow with “jquery.cycle.all.js”
- Where is the order of a menu saved in the database
- Insert a div class inside wordpress menu
- Using Foundation 5 in WordPress Administration Area
- Output menu title
- Retrieve Menu name for nav_menu_item
- Wrapping link and .sub-menu with wp_nav_menu
- How to add a element with walker menu right after begin of the navigation tags?
- I have an old version of jQuery showing up. How do I figure out where it is coming from?
- Bootstrap button menu on wordpress
- Add Labels to Admin Menu ( How To )
- Want to add different text after each menu item
- How to create a menu item which is not a page
- Plugin Scripts no loading on options page
- Close Fancybox, sumbit form data and redirect
- Custom Menu not functioning properly
- How to use wp_nav_menu with hashtag links?
- How do I include javascript/jquery image resizing with wordpress?
- styling wp_nav_menu – horizontal, sub-menu drop downs
- Show children (sub-navigation) of active menu item only
- Hide a menu on posts
- Rename menu items for All except super admin
- remove menu items if user can’t read
- Localizing methods for jQuery append prepend wrap parent
- Why Isn’t My WP_Nav_Menu returning false?
- How can I make a menu link visible only to admins (without plugins)?
- Ajax Validation for reCaptcha
- magic “MENU” button under Twenty Twelve theme
- How to add a page to header that is outside of WordPress?
- Get current menu item label for specific parent menu [closed]
- Remove first separator in wp_nav_menu
- Menu Arrow for Child Element
- changing host.. data loss
- Custom menu with different behavior for every item
- I’m using wp_nav_menu to display my menu, but I want one more link in there that is a hardcoded link. How can I do this?
- Theme Location empty
- Theme only supports one menu? [closed]
- wp_nav_menu check both hierarchy fail?
- Responsive dropdown menu with smaller screen sizes
- How do I make my wordpress post appear in a mouse hover preview?
- Replace the slug of parent pages with # [closed]