Using wp_enqueue_scripts
You should use a proper hook to enqueue/dequeue your scripts, to ensure that it works flawlessly. A proper plugin/theme uses wp_enqueue_scripts
to do this, so you should do the same. Wrap your code inside a function, and bind it to this action hook. Also, remember to set the priority to something that makes sure it will override the others.
// Setting the priority to 999 to make sure it runs
// after every other script is enqueued
add_action('wp_enqueue_scripts', 'enqueue_my_scripts', 999);
enqueue_my_scripts () {
if ( is_page_template( 'specific-template.php' ) ) {
// Your code here
}
}
Related Posts:
- How to load scripts/styles specific for a page
- Dequeue Scripts and Style for Mobile not working?
- Enqueue script o style only if a template part is loaded
- If is multiple page templates
- Enqueue scripts not working with if is page conditional tag in functions.php
- Only let plugin add actions to wp_head & wp_footer on single posts
- enqueue styles for only mobile wp
- Scripts not loading when using the wp_enqueue_scripts action
- Why does get_template_directory_uri() not include “www”, only for enqueued stylesheets?
- Theme JS is available but theme CSS isn’t
- Advanced method to control cache of enqueued style/script
- Add custom css file after plugin css with WordPress Child Theme functions.php
- wp enqueue style on about us page
- Test CDN link from function.php or wp_enqueue_script/style?
- How do I dequeue a Stylesheet, stored in an ‘Assets’ folder?
- Why is style.css not loading through the functions.php
- custom post with loading script per single post
- using enqueue_script in a shortcode isn’t working
- WordPress Enqueue for homepage only, functions.php, wp-framework
- Enqueue Script with data attributes
- How to enqueue every script in a folder automatically?
- TinyMCE custom stylesheets for different post types
- is_front_page not working in functions.php
- Most elegant way to enqueue scripts in function.php with foreach loop
- wp_register_script not loading as expected
- Problem using is_single() to enqueue script from functions.php
- Enqueue less file not working in child theme?
- I created a child theme and it doesn’t work for some of the css files
- Enqueuing External Javascript functions.php
- Child Theme Not Overriding Parent Theme
- How to enqueue JavaScript for specific WordPress pages only?
- Enqueue styles after a plugin
- How to override enqueued styles using a child theme
- Enqueuing Script in functions.php vs on the page
- Dequeue script in template isn’t working
- How do I get a child theme to load scripts from the parent theme?
- Load JS Script only for custom post types
- Register and enqueue style.css custom theme
- wp_is_mobile dequeue not working
- Why won’t my scripts load?
- Enqueue Style Only On Certain Pages Not Working
- Not sure if enqueuing js scripts properly
- Remove stylesheets from Campaign Monitor plugin
- how to en-queue jQuery to load before the tag
- jQuery does not work
- enqueue_script with filemtime javascript not working
- add_action wp_enqueue_script priority level only works for admins
- linking stylesheets and scripts with functions.php
- Split Media Queries in different files!
- Some questions about how proper add 2 CSS file in a WordPress theme?
- In jquery use php variable to execute an enqueued jquery file
- Run a jquery script on on a certain template page
- wp_enqueue_script | Help me figure out what is causing jQuery is not defined
- Load JS file only in specific template
- Parent theme styles overriding child theme CSS [closed]
- Proper Way to Load stylesheet on Condition
- How to load jQuery in TOP of wp_footer?
- get_template_directory_uri() links to child theme not parent
- How to pass variables from one function to another or combine functions
- video.js not enqueueing?
- Include Jquery libraries in wordpress theme?
- Problem enqueuing scripts on not single posts
- Call two different function.js depending on page
- Enqueueing a code block from an options framework
- Why I can’t load my JavaScripts using an hook inside my functions.php file?
- Enqueueing scripts selectively & activation where needed
- Why is this function crashing my wordpress installation? [closed]
- colorbox not loading in
- wp_enqueue_script() not working
- How to use wp_enqueue_script properly?
- Get webpack to work on child theme
- WordPress wp_dequeue_script remove all other scripts
- Is it possible to load recaptcha script only in url with fragment identifier (#)?
- How to reference different css (bootstrap) stylesheets for the header and body of a page?
- CSS style and app.js not loading
- How to make the RTL.css the dominant css code?
- Why does my wp_enqueue_script() only insert the script for logged in users
- How do I create a child theme from PowerMag theme
- WP Enqueue Script Error
- Child Theme not loading multiple stylesheets
- I need to completely ‘wp_dequeue_script’; what’s the best way?
- True parameter but jquery register in header and not in the footer with wp_register_script
- Javascript and Stylesheet in child page
- WordPress Jquery+scripts enqueue issue
- 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
- Exclude javascript in certain page url and all following url’s after forward slash
- Print all inline styles to head
- java script error Uncaught SyntaxError: Unexpected token ILLEGAL
- Using array page name together with page id to deregister script
- wp_enqueue_scripts called twice?
- Should I use `get_stylesheet_uri()` or `get_template_directory_uri()` when calling my CSS Stylesheet?
- Why my wp_enqueue_script doesnt work on some page?
- How to fix enqueue_styles error for a twenty-seventeen childtheme
- wp_head not injecting css
- WordPress – Notice: Function wp_enqueue_script was called incorrectly
- dynamically import array from another js file in WordPress
- Auto updating JavaScript dependancy in functions.php
- wp_script_add_data not working