- Start by putting your JS in an appropriate .js file in your theme directory.
- Use the wp_enqueue_scripts hook (this is where you will enqueue/load any of your custom javascripts).
- Within that hook, use wp_enqueue_script() to load your script(s).
Example:
add_action( 'wp_enqueue_scripts', 'enqueue_my_stuff' );
function enqueue_my_stuff () {
wp_enqueue_script('slug_for_your_script' , get_template_directory_uri() . '/path/to/yourscripts.js', array('jquery') );
}
Related Posts:
- Adding javascript to functions.php causes problems with my template
- Add tags to the section via functions.php
- Where and how to put inline js in pages
- Does WordPress Development Mode Exist (with not minified JS)?
- Apply jquery script to only woocommerce product pages and categories
- Change meta tags programatically
- Run Product Filter Javascript On Page Template
- Enqueuing External Javascript functions.php
- How to enqueue JavaScript for specific WordPress pages only?
- How to add iOS & fav icons to the theme?
- Defer all js except certain ones in functions.php file
- Enqueuing Script in functions.php vs on the page
- Properly applying nonce to a form using AJAX
- Clean-up script tags
- Trying to inject twitter metadata into using wp_head action in functions.php – get_the_excerpt() returns null
- wp_enqueue JavaScript in child-theme (ReferenceError) using Search & Go
- Why is my Gutenberg block returning an error after initial save?
- jquery won’t load in footer
- How do I edit wp_head and/or functions.php to remove rss-feed which isnt used and dont validate?
- How to properly add NPM packages and integrate them in WordPress?
- How to filter a table in post content without plugins? [closed]
- Get Current User info using wp_localize_script, in functions.php
- How to get the post_name when in preview?
- Replace menu links with # and add name to its li
- wp_is_mobile dequeue not working
- Why won’t my scripts load?
- Loading CDN that requires jQuery in WordPress
- How to hide unused profile fields?
- wp_register_script(… $in_footer = true) not working
- Passing a variable via wp_head and then calling it on the page
- Scripts not appending to element in AJAX call – why?
- call of javascript function to external url always blocked by cors
- Including a specific Javascript Script in a template. Is my code correct?
- How to search using ajax for exact phrase or words in an input field?
- how to en-queue jQuery to load before the tag
- Overwriting the menu break points of twentysixteen in child theme
- How do I remove the date and category form my portfolio pages
- I can’t enqueue my scripts – They literally aren’t being added to my site
- Remove adjacent_posts_rel_link under 3.2?
- I have problems with loading javascripts
- Auto Generated HTML source code formatting
- Dequeue script to prevent javascript event conflict on wordpress child theme
- javascript and css links not working on sever
- Run a jquery script on on a certain template page
- How can I pass a shortcode value to the head in wordpress functions.php
- The correct way to add a JavaScript in the functions.php [closed]
- Different favicon on different pages
- Javascript not loading after the document ready
- Theme JS is available but theme CSS isn’t
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- Need help with customalert that it would read on a normal page, but not in WordPress
- How to load jQuery in TOP of wp_footer?
- Include Jquery libraries in wordpress theme?
- Linking Javascript in functions.php file
- Dequeue scripts in IE7 only using functions.php
- Why a SlideShow (made using JQuery FlexSlider) can’t work if I load it form functions.php but work if I load it from my footer.php file? [closed]
- Creating multiple category drop down
- Function to echo (or display?) wordpress tags in the head section
- Creating a custom wordpress widget and stopping js from running twice(once in active widget once in widget selector)?
- How do I find the code executed when wp_head() is called?
- How to setup a popup registeration page in wordpress with function.php
- Custom attributes to javascript tags
- wp_enqueue_script() not working
- How to change text color depending on the number value (Using javascript)
- Add custom taxonomy using JS in post editor
- wp_set_object_term via js btn frontend
- Display Script in Header When URL Variable Present
- Running javascript without hooking wp_head
- Hide author info in single posts by certain users
- Ajax in plugin fails – but only on one blog – no idea why
- How to add javascript code into Divi child theme?
- Changing the default view of “The Events Calendar” for mobile
- How To Display Author Popup on Entry Meta (Genesis Framework)?
- Help wiht adding fullcalendar.io to a WordPress page
- Multiple Notifications SetInterval
- Placing CSS/ JS into the header or footer (inline) – trying to apply to several templates
- Edit meta fields from within template
- Get child-pages slugs of current page into js-file
- admin-ajax.php & my wp-admin folder url showing in header
- Some code is added automatically to my site’s header – what is it?
- wordpress ajax is not working for dropdown selection
- Javascript and Stylesheet in child page
- Automatic add space if user enters number(any digit)
- Search and Replace Script Loader in Head Only Works in Footer
- custom COOKIE on custom page
- custom post with loading script per single post
- Why are some custom javascript files working but some are not
- WordPress Javascript Widget jQuery Dependency Issue
- java script error Uncaught SyntaxError: Unexpected token ILLEGAL
- Echo a div to header.php from functions.php
- How do I get my nav menu to show sub pages?
- Why wp_ajax hooks doesn’t work?
- comment_post function with js not running
- Animated Accordion [closed]
- wp_head not injecting css
- Get all users from role and add to dropdown (select) – wordpress, javascript
- Can’t find function which is called in a wordpress theme
- dynamically import array from another js file in WordPress
- WordPress enque the same script causes the setInterval not to work
- iOS and ajaxComplete