Enqueue styles through the wp_enqueue_style function vs link tag inside header.php

Three good reasons to use the enqueue functions over hard coding are to eliminate duplication, avoiding library conflicts, and handling dependencies:

  • Duplication: If, for example, you hard code a link to jQuery, and then install a plugin which also enqueues the jQuery library, you’re site will be loading the same library twice, which will affect the page load speed, amongst other things.
  • Library conflicts: Much like duplication, but the plugin may be loading a different version of jQuery, which results in your page trying to load two conflicting versions, which could cause serious page problems.
  • Handling dependencies: If you create a custom script which relies on a javascript library, you can add the dependency as a parameter of the enqueue function, which will ensure that the required library is loaded before the custom script. Easy enough to do with hard coding, but easier to keep track of with wp_enqueue_style().

Further reading here: https://www.seedprod.com/enqueuing-styles-scripts-wordpress/

Leave a Comment