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
- Is there any global functions.php file which works for any theme?
- Display random categories on the front page (Finding and Editing Theme Functions)
- Apply jquery script to only woocommerce product pages and categories
- Replacing select2 in admin backend for all selects
- 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
- Enqueuing Script in functions.php vs on the page
- Unable to get_the_content(); of a post in WordPress via AJAX
- Theme-Config tab in admin Pannel?
- How to load some jquery code to make validation in the theme customizer?
- 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 add an image to the footer?
- Hook specific functions if on a specific admin page
- Activate small php condition at footer over page template
- functions.php mistakenly deleted
- Echo tags used to describe the theme
- 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
- Not sure if enqueuing js scripts properly
- How to stop twenty fifteen theme from cropping featured images?
- Theme functions.php file auto delete everyday [closed]
- How to remove style attribute in WordPress RSS output?
- Is there an alternative to get_template_directory_uri()?
- create filter in functions.php
- Add Custom Background Properties to Customizer
- How to search using ajax for exact phrase or words in an input field?
- 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
- WordPress PHP Conflicting User Sessions
- PHP mixed with some JS code to update WordPress theme settings
- 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
- 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]
- In jquery use php variable to execute an enqueued jquery file
- 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?
- How can i unload effect.min.js file?
- wp_enqueue_script | Help me figure out what is causing jQuery is not defined
- Redirect website domain (including all pages) to external URL after Popup message (few seconds)
- Check from functions.php if function exists in footer.php
- Getting the teaser text without overriding global variables
- Default Nav Highlight
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- How to load jQuery in TOP of wp_footer?
- Passing Jquery value to WordPress function
- “options.php” not found
- WordPress can’t get jquery/unslider to work
- How to override this theme function in child theme
- Include Jquery libraries in wordpress theme?
- get_template_directory() – references parent theme directory
- Why I can’t load my JavaScripts using an hook inside my functions.php file?
- How do I preserve changes to a theme’s functions.php across updates?
- How to setup a popup registeration page in wordpress with function.php
- What function actually renders the wp_admin_bar ? How can I call it?
- Get URLs for AJAX Filter Checkboxes WordPress
- wp_set_object_term via js btn frontend
- Populate Product Regular Price with a calculated ACF Field Value
- Header menu aligned right on all pages except for single-post page [closed]
- Ajax Form Issues using Lightsail (AWS)
- What is the earliest Hook a Script can use?
- WordPress does not load jQuery
- post value to function with Ajax and jQuery
- CSS style and app.js not loading
- Setting Up Child Theme To Take Priority
- wp_footer hook causing text to show on bottom of page
- Multiple Notifications SetInterval
- Shortcode Initialization in a Custom Theme
- How do i create a search option for pdf’s only
- Load scripts into an AJAX div
- Load scripts into an AJAX div
- True parameter but jquery register in header and not in the footer with wp_register_script
- Why are some custom javascript files working but some are not
- WordPress Javascript Widget jQuery Dependency Issue
- jQuery HoverIntent is not a function
- How does child theme functions.php work with parent theme functions.php? Is it like CSS? [duplicate]
- Ajax call does not work for this custom code
- Having problems loading Jquery in functions.php
- shortcode inside post called by ID does not render as expected
- Add custom css to theme
- AJAX values converted to PHP Variables?
- How to get postId from the argument $block when register_block_type()?
- How to automatically load Google Fonts on pages only as they’re used?