giftbikes.blogg.se

Enqueue script wordpress
Enqueue script wordpress






Wp_enqueue_script( 'first', get_theme_file_uri( 'dist/scripts/first.js' ),, null, true ) Or you can enqueue a file with a handle 'first' and then use it as a dependency for your second file called 'second' like this: can set dependencies for the scripts you load, so for example you could add jquery as a dependency for your main.js (not covered in this post).The main benefits for using wp_enqueue_script() are: Wp_enqueue_script() works as an additional layer for these wp_head and wp_footerfilters. Would echo  to the place where you call the wp_head()function.Īnd you could definitely do something like this: ' Īdd_action( 'wp_footer', 'main_js_to_wp_footer', 100 ) īut there’s still a better way to enqueue scripts into your WordPress theme. So for an example this: "Īdd_action( 'wp_head', 'hello_world_comment', 100 ) Wp_head() and wp_footer() are basically places where you can echo things through wp_head and wp_footer hooks. They’re used placed into your header.php and footer.php in a way that those files combined would look like this: To understand fully how wp_enqueue_script() works we should take a look at the wp_head() and wp_footer() functions. In this article I’m going to show you how, why and when you should use wp_enqueue_script() to load your JavaScript files. While this obviously works, I later discovered that there is a better way to enqueue scripts built in WordPress core. In the early days in my career as a WordPress dev I used to load my JavaScript files like this: /wp-conteht/themename/dist/main.js">








Enqueue script wordpress