Scripts and stylesheets should always be loaded in the head or in the footer via the wp_enqueue_scripts action hook
. wp_enqueue_scripts
is the proper hook to use when enqueuing items that are meant to appear on the front end
The init
hook executes before wp_head
which is to early for script to load in the header. The wp_enqueue_scripts
action hook is executed right after wp_head
, allowing scripts and styles to be loaded properly. This also have the benefit of naming script dependencies and ordering scripts and styles to load properly
Related Posts:
- What is the earliest Hook a Script can use?
- True parameter but jquery register in header and not in the footer with wp_register_script
- Extract image from content and set it as the featured image
- Add action hook conditionally – only when home.php in use
- How can I tell if I’m on a login page? [duplicate]
- How to hook into the quick edit action?
- WooCommerce add_action hook results in 500 error
- Enqueuing Script in functions.php vs on the page
- Passing arguments to my function with do_action and add_action is not working
- Accepted arguments value in hook functions
- Which action hook to use for function?
- Modify a function without editing template
- Don’t delete a page if it holds users
- Not sure if enqueuing js scripts properly
- Which action does wp_update_user triggers?
- How can I get my Script to work on the Login page?
- Trigger a custom function when option are saved in admin area
- how to en-queue jQuery to load before the tag
- Attempt to change jQuery version caused White Screen of Death
- Override the WordPress core function wp_referer_field
- Scripts not loading when using the wp_enqueue_scripts action
- Is there a way to prevent a function/method from being called outside a specific hook?
- In jquery use php variable to execute an enqueued jquery file
- Run a jquery script on on a certain template page
- Adding code before post title with the_title produces weird results
- wp_enqueue_script | Help me figure out what is causing jQuery is not defined
- Add back in child theme what the parent theme removed with remove_action
- This code works, but the way I integrated it is breaking the media uploader. How can I integrate it properly?
- How to load jQuery in TOP of wp_footer?
- Changing where my author box is printed
- Insert Content Before div#main from the functions.php File
- Include Jquery libraries in wordpress theme?
- Replace admin header logo with an image
- Why I can’t load my JavaScripts using an hook inside my functions.php file?
- colorbox not loading in
- How to use wp_enqueue_script properly?
- Does hook have an effect on increasing the page load?
- Save_post – Warning: Cannot modify header information
- post value to function with Ajax and jQuery
- How Do I Unhook This Parent Theme Function?
- WordPress hooks to call a function inside a construct
- WordPress Jquery+scripts enqueue issue
- delete_term is not working properly with add_action()
- Function attached to cron job not running but will run if called manually
- Function added using `add_action()` not being called
- Change CSS for logged in users
- Always the Latest google jQuery instead of default WordPress jQuery
- Add a jQuery Function
- Difference b/w Simple function call & do_action call
- jQuery code not working when included in functions.php
- enqueue_script with filemtime javascript not working
- Why does re-using this function not work? [closed]
- using jQuery on only one page
- using enqueue_script in a shortcode isn’t working
- Using array page name together with page id to deregister script
- enqueue script if page is not equal to
- Highlight posts currently being edited on multiple editor site?
- function to return comma separated list of meta values
- Add custom fields after post/page title
- Ajax call does not work for this custom code
- Force resize for all video content
- wp_enqueue_scripts called twice?
- Unhook the comment form in Buddypress
- How do I get my nav menu to show sub pages?
- Having problems loading Jquery in functions.php
- Why wp_ajax hooks doesn’t work?
- add query string to all pages after user logged in
- Remove snippets of JS from core
- Do something when user creates post (that’s pending)
- Why my wp_enqueue_script doesnt work on some page?
- How can I append and prepend something to all post hyperlinks without using ::before or ::after? PHP hook solution?
- Owl Carousel and WordPress Integration Via WP_Enqueue
- add variable to actions/functions across different files (woocommerce)
- Why functions metaboxes is causing White Screen in Admin [closed]
- How do I add functionality to images?
- AJAX values converted to PHP Variables?
- How to hook wp_mail to add a custom email as BCC for each sent email?
- image_size with respect to aspect ratios
- Animated Accordion [closed]
- WordPress – Notice: Function wp_enqueue_script was called incorrectly
- dynamically import array from another js file in WordPress
- HELP: Code To Check Status And Write Debug Entry
- Auto updating JavaScript dependancy in functions.php
- Loading newest dependency javascript module file in functions.php
- Get category of post inside save_post hook
- Create section wit form
- iOS and ajaxComplete
- wp_script_add_data not working
- Log in and out using custom pages, no logout confirmation and redirects for logging in and out 2023
- Is there a hook that I can use when a fatal error occurs?
- Copy and Modified WooCommerce function is_coupon_valid [closed]
- How to get variable from other function inside class function using add_action for Ajax call
- How can I able to exclude ‘Category’ and ‘Tag’ slug from the URL in WordPress without reloading to new site?
- Redirecting after login except for a specific page
- Submit CF7 form programmatically with WP-Cron?
- disable a specefic sidebar when user is log out
- wp_update_post breaks my function
- Add 2 links in between the navigation using the Breadcrumb Navxt plugin hook
- is there a list of actions on WordPress
- Remove Actions/Filters added via Anonymous Functions