Common Mistakes When Adding Stylesheets and Scripts
A large number of theme and plugin developers can make the mistake of directly adding scripts or inline CSS into themed and plugins. Often, you can mistake the wp_head function for loading scripts and stylesheets. Using the wp_head may seem like an easy option, but this way is incorrect. Also, using this option will often cause more conflicts. A good example of this is if you choose to load the jQuery manually whilst another WordPress plugin loads jQuery using the proper method. This makes the jQuery load not once but twice. If this happens on every page on your site, then this can have a negative impact on the speed and performance of your site. In some cases, it’s also possible that two different versions will be created, leading to further conflicts. We’ll now take a look at the correct way to add your stylesheets and scripts.
Enqueue Scripts and Styles for Your WordPress Site
When it comes to using enqueue scrips, you’ll need to provide all the parameters in wp_register_script and then use the action hook to load the script.
Enqueue Styles in WordPress
Here, instead of using the wp_enqueue_script, you’ll be using wp_enqueue_style yo add your stylesheet.
We hope that this article has given you a better understanding of the importance of enqueuing both your scripts and styles. If you’re interested in this as a novice developer, you may also want to take the time to study the different source codes attached to the top WordPress plugins.