Enqueuing Scripts & Stylesheets in WordPress Local Environment

Rachelpadworski
1 min readApr 20, 2021

Lost on where to call your scripts and stylesheets in your WordPress local environment? Outside of WordPress developers say to place your script calls and stylesheet calls within <script> and <link> tags in the HTML Footer or Head.

When creating a WordPress project, they need to be enqueued. The best place to put these is in the Functions.php file.

Enqueuing style.css

Instead of placing your style.css within a <link> tag in the Head, you’ll need to call it in the Functions.php file using something similar to this:

wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slider.css',false,'1.1','all');

Enqueuing a Script

Instead of placing your JS script tag in the Footer, it needs to be added to the Functions.php file using something similar to this:

wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array ( 'jquery' ), 1.1, true);

Enqueuing Multiple Scripts and Stylesheets

For enqueuing multiple scripts and stylesheets, you can use the add_scripts() function. Within this function you can call the wp_register_script, wp_deregister_script, wp_enqueue_script, wp_enqueue_style functions. After the function, add the action using add_action(‘wp_enqueue_scripts’, ‘add_scripts’);

For more detailed information, check out this link:

https://developer.wordpress.org/themes/basics/including-css-javascript/

--

--