Example for themes
I would recommend using wp_enqueue_script with get_theme_file_uri this allows child themes to overwrite this file.
get_theme_file_uri() function
Searches in the stylesheet directory before the template directory so
themes which inherit from a parent theme can just override one file.
wp_enqueue_script( 'example-script', get_theme_file_uri( '/js/example-script.js' ), array('jquery'), null, true );
Example for plugins
wp_enqueue_script( 'example-script', plugins_url('/js/example-script.js', __FILE__), array(), null );
Related Posts:
- Move WordPress native javascript to bottom of page?
- RequireJS in custom theme. Working Example
- How to get a jQuery script to run on a page?
- Including javascript for a shortcode
- Asynchronous Javascript Loaders
- wp_enqueuescript won’t load in footer even with true value set?
- How wp_enqueue_script works?
- How do I get my page to load the jQuery UI Effects library?
- Script won’t execute in the media manager
- How to properly add Bootstrap and JQuery Javascripts?
- Searching multiple tags and adding jQuery dependant script onto page template?
- Plugin Scripts no loading on options page
- How to enque js script in footer that are not in .js file?
- Loading scripts on a single page plants the script in the footer
- Using WP functions inside javascript
- Including Older Version of jQuery for IE7/IE8
- How To Include JavaScript Files Only In Single Posts?
- How to make JQuery load on top of head tag before everything
- JavaScript code do not works on online server
- Bootstrap with separate js File
- How to add JS snippet before closing tag?
- Enqueue javascript that inserts custom php widget into jQuery-constructed div
- How to Run a jQuery Script after a Javascript Script has Finished in WordPress
- javascript not loading in wordpress
- bootstrap-slider.js by seiyria not working in wordpress
- How to set time delay in javascript
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- My javascript is returning this error: $.ajax is not a function
- JavaScript: filter() for Objects
- JavaScript Loading Screen while page loads
- How to get client’s IP address using JavaScript?
- javascript function wait until another function to finish
- Simple throttle in JavaScript
- Enable & Disable a Div and its elements in Javascript
- Javascript – ERR_CONTENT_LENGTH_MISMATCH
- The ‘describe’ keyword in javascript
- Is there a way to enable Cross-Origin Resource Sharing for WordPress’ ajaxurl?
- force enqueue script to be first in order of prominence
- How to dequeue a script?
- Make jQuery library load before plugin files
- How to get attachment id as soon as it is uploaded through media uploader in jquery?
- Ajax call does not activate callback function
- How to handle multiple instance of “send_to_editor” js function
- Using ‘$’ instead of ‘jQuery’ in WordPress
- Automatically decrease font size for long words
- Add `datetimepicker` to form
- Deregister WordPress jquery on specific page
- Gravity Forms loading jquery
- Javascript included but alert() function not working
- Trying to get single posts to load on the front page via ajax
- Use js script from one plugin in another plugin
- Ajax not firing properly using Firefox, but works in Chrome
- wp_enqueue_script won’t load in header?
- jQuery Hoverintent plugin in TwentyEleven Menu [closed]
- Execution of JavaScript on save post
- How do I activate jQuery/script on demand?
- Adding jQuery dependency prevents my script from enqueuing/loading
- Add colorpicker to featured image
- Gravity Forms not loading under https, jQuery is not defined
- Can’t move jQuery to footer
- Using multiple versions of jQuery while still calling it like WP likes
- wp_enqueue_scripts hook is not being called
- WordPress Jquery Fade in, Fade out effect
- wp_ajax unauthenticated and authenticated
- WordPress ajax function parameter value not being passed
- Is it safe to include a javascript file in a template’s php file?
- Override default jquery ui library with newer version
- Including Javascript options
- Add a Fancybox automatically to post type “post” images
- enqueued script with jquery dependency not getting jquery
- WordPress customizer refresh screen after save
- Creating multiple enclosing shortcodes and fixing JS issues on click
- Enqueue Google CDN jQuery in Footer
- How to undo deregister script and use local versions?
- Can’t load a class into WordPress post editor’s content field
- ‘jQuery is not defined Error’ appearing in load-scripts.php
- WP_enqueue_script() loads them always in wp_footer()?
- Implementing lazy loading in homepage posts instead of pagination
- JSON output returns page source code [closed]
- Is it necessary to enqueue jquery?
- jQuery not available to other scripts
- WordPress Ajax problem with undefined url
- Correct way to write jQuery functions in WordPress
- Dealing with a library that depends on jQuery
- Move jQuery to the bottom of the page whilst keeping the WordPress jQuery
- start.js:45TypeError: Not enough arguments on Safari [closed]
- How to Dynamically Load Content Into Body of Bootstrap Modal Window?
- I want to import my Json file into a custom made display-modal. How do i link my Json file?
- Help with a jQuery Carousel
- Using bootstrap-slider and bootstrap-switch in wordpress admin panel
- WordPress jquery files not being enqueued
- TinyMCE 4 remove/add attributes for all images
- Trouble with WordPress Ajax Login System – 302
- Why does javascript works only if logged in?
- How does WordPress handle HTML Tables interaction with jQuery
- Javascript stopped working [closed]
- Why is my WordPress loading old version of JQuery?
- Fall Back Google CDN in JavaScript
- wp_enqueue doesn’t work