You need to load your scripts in the footer so you’ll need to add them to the functions.
This method works for parent themes dependent on jQuery.
For child themes
Change:
get_template_directory_uri()
To
get_stylesheet_directory_uri()
Example code for parent themes:
function wpsites_load_scripts() {
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpsites_load_scripts' );
The 5th parameter determines where the script is loaded:
$in_footer
Normally, scripts are placed in of the HTML document. If this parameter is true, the script is placed before the end tag. This requires the theme to have the wp_footer() template tag in the appropriate place.
Default: false
Source http://codex.wordpress.org/Function_Reference/wp_enqueue_script
Related Posts:
- Add external js file to footer with id
- Move jQuery and Migrate to footer?
- How can I change the do_action function in footer (copyright area)
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- 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]
- Moving CDN jQuery to footer does not work?
- remove_action on after_setup_theme not working from child theme
- How to load scripts/styles specific for a page
- Is there any global functions.php file which works for any theme?
- Child theme – Overriding ‘require_once’ in functions.php
- Display random categories on the front page (Finding and Editing Theme Functions)
- Issue with get_theme_mod returning a blank value instead of the saved value
- AJAX handler throws 400 (Bad request) – why?
- ajax live search for post title
- Hourly Routine Not Firing ( wp_schedule_event() )
- Apply jquery script to only woocommerce product pages and categories
- which is the function that removes accented vowels?
- Replacing select2 in admin backend for all selects
- How to save Uploaded image in custom option panel?
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- Theme Demo in live Site
- Customising widget titles/headings in WP 5.8
- How do you completely remove the default header and footer using functions.php?
- Child Theme Not Overriding Parent Theme
- jQuery plugin function is not a function
- Display a function using AJAX
- Enqueuing Script in functions.php vs on the page
- Where does function_exists() look to decide whether a function exists? [closed]
- Unable to get_the_content(); of a post in WordPress via AJAX
- Theme-Config tab in admin Pannel?
- Ajaxing function in widget class
- How to load some jquery code to make validation in the theme customizer?
- woocommerce target button with class after ajax update
- jquery won’t load in footer
- WordPress doesn’t Load JQuery Now? Do I need to enqueue JQuery also?
- Is It wrong to use oop approach on functions.php?
- Woocommerce checkout field maxlength, make input number field only (postcode)
- PHP files included in functions.php don’t seem to work
- How to remove howdy dropdown menu content
- how to add an image to the footer?
- Hook specific functions if on a specific admin page
- Replace menu links with # and add name to its li
- Loading CDN that requires jQuery in WordPress
- Activate small php condition at footer over page template
- functions.php mistakenly deleted
- wp_register_script(… $in_footer = true) not working
- Echo tags used to describe the theme
- changing behaviour of get_search_form
- Child Theme files – what is needed?
- Right way to update widget on dynamic new input field
- Problem only while using require_once() within functions.php
- Translation of theme using child theme
- Not sure if enqueuing js scripts properly
- Wp_query function to search from product_title ‘OR’ product tags name
- Allow Post Author to be 0 on Update
- Trouble with adding a wp_enqueue_script on wordpress
- How to stop twenty fifteen theme from cropping featured images?
- Theme functions.php file auto delete everyday [closed]
- WP Ajax Function Always Returning undefined
- Scripts not appending to element in AJAX call – why?
- How to remove style attribute in WordPress RSS output?
- WordPress website Rs changed to currency symbol
- Is there an alternative to get_template_directory_uri()?
- How to change the order of Jquery in the footer of my theme?
- create filter in functions.php
- Add Custom Background Properties to Customizer
- Functions in custom theme
- How to search using ajax for exact phrase or words in an input field?
- how to en-queue jQuery to load before the tag
- Jquery implementation not working on page reload
- Parse error after modifying the template menu [closed]
- I can’t enqueue my scripts – They literally aren’t being added to my site
- Attempt to change jQuery version caused White Screen of Death
- WordPress PHP Conflicting User Sessions
- PHP mixed with some JS code to update WordPress theme settings
- Load jquery only for certain pages in the backend
- Change CSS for logged in users
- Always the Latest google jQuery instead of default WordPress jQuery
- Add a jQuery Function
- jQuery does not work
- Function that outputs second theme url
- using jQuery on only one page
- Which function required?
- Can’t call Javascript function – scope?
- Changing parent element’s class or style
- Enqueuing latest version of jQuery into a child theme returns a blank screen
- echo custom fields with AJAX
- Not all CSS elements transferring via parent to child?
- unnecessary request call for js and css after calling wp_dequeue_script
- Adding jQuery datepicker to Custom Post Type Metabox [closed]
- Some questions about how proper add 2 CSS file in a WordPress theme?
- In jquery use php variable to execute an enqueued jquery file
- Turn get_posts as string into an array for use in theme admin options
- Run a jquery script on on a certain template page
- Filter nav menu items HTML tags and wrap inner text with span
- Add php code to wp_print_scripts?
- Insert nofollow in a “Powered By” link, except in the homepage [closed]
- How can i unload effect.min.js file?
- wp_enqueue_script | Help me figure out what is causing jQuery is not defined
- Can’t switch to a child theme using filters template, option_template and option_stylesheet