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()
- Remove Actions/Filters added via Anonymous Functions
- Check if post is being published for the first time, or is an already published post being updated
- How to influence the information displayed on widget inside wp-admin
- WordPress Theme Update Action?
- Is there a hook or function I can use to display all theme files being used on a current page?
- Using a private method as an action callback from within a class
- Implementing DNS Prefetching with WordPress
- Replacing select2 in admin backend for all selects
- Set default options for inserting media
- Enqueuing External Javascript functions.php
- Move jQuery and Migrate to footer?
- Gravity Forms field entries into wp_query loop [closed]
- Get current page_id before loop, in functions.php
- Custom HTML in specific category single page and its descendant categories
- Inserting a functions output after the content
- Is there an alternative to get_template_directory_uri()?
- How to search using ajax for exact phrase or words in an input field?
- Exclude some scripts from removing unique scripts from head function
- Modify custom field input data before creating a new post
- Footer disappears when using the_content ( )
- I can’t enqueue my scripts – They literally aren’t being added to my site
- (Woocommerce) Order by price when entering specific category
- Create a post builder skin in a plugin
- Call to undefined function is_home() or any conditional tags
- How to remove a class function from a plugin by using remove_action()?
- Theme JS is available but theme CSS isn’t
- Passing Jquery value to WordPress function
- Is it possible to use add_filter in an included file in the child theme’s functions.php?
- Problem in using Customizer
- Problem enqueuing scripts on not single posts
- How to conditionally add a widget via a hook in functions.php
- Enqueueing scripts selectively & activation where needed
- Changing the text of Upload/Insert on Posts and Pages Screen
- Which hook to use when adding ajax to viewer-facing side?
- Get URLs for AJAX Filter Checkboxes WordPress
- Warning at top of website & top menu gone
- Is it possible to load recaptcha script only in url with fragment identifier (#)?
- How do I trigger WP CLI DB export using a PHP function?
- WordPress does not load jQuery
- Multiple Notifications SetInterval
- How do i create a search option for pdf’s only
- I need to ‘wp_dequeue_script’ and ‘styles’ and ADD a bunch of other css and js
- True email confirmation for registration (keeping unvalidated users from user table)
- Fatal error: Call to undefined function add_action() – an untouched problem
- I can’t enqueue Suggest.js in frontend – not added
- Different body image backgrounds on different pages, posts and categories
- How to wp_enqueue_script with html?
- wp_enqueue_script only works outside of action
- Init hook for header send
- java script error Uncaught SyntaxError: Unexpected token ILLEGAL
- Highlight posts currently being edited on multiple editor site?
- How do I add functionality to images?
- AJAX values converted to PHP Variables?
- Get category of post inside save_post hook
- iOS and ajaxComplete
- Log in and out using custom pages, no logout confirmation and redirects for logging in and out 2023
- Copy and Modified WooCommerce function is_coupon_valid [closed]