How to use wp_enqueue_style() in my WordPress theme?

How to use wp_enqueue_style() in my WordPress theme?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Integrating wp_enqueue_style() for LESS in WordPress Themes

You are dealing with a fundamental shift in how WordPress handles assets. The <link> tag you currently have in your header.php is a static HTML element that points to a compiled CSS file. When using the WP-LESS plugin, the workflow changes because the .less source files need to be processed by the build tool before they can be served to the browser. You cannot simply point WordPress to a raw .less file and expect it to render styles; the server-side compiler must run first.

The function wp_enqueue_style() is not a replacement for your <link> tag in the sense that you delete the tag and forget about it. Instead, wp_enqueue_style() is the mechanism used during the WordPress initialization cycle (specifically inside hooks like wp_head) to register asset dependencies and generate the correct URLs automatically.

Here is how you integrate this into your theme. You should place the function call inside a PHP block within your header.php file, ideally wrapped in a conditional check or a standard hook action. The most common location is immediately before or after the opening <head> tag, or specifically hooked to wp_head.

// Inside header.php
<?php wp_head(); ?>

However, to use wp_enqueue_style() effectively with WP-LESS, you must register the style in a specific function that runs early enough for WordPress to process it. Typically, this goes in your main theme file (functions.php) or a dedicated template loader.

The syntax you proposed is close, but there are critical distinctions regarding how you reference the file and handle dependencies. The standard implementation looks like this:

function mytheme_enqueue_styles() {
    // Register the style from the compiled LESS output or the plugin's generated CSS
    wp_enqueue_style( 'mytheme-style', get_stylesheet_uri(), array(), null );
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_styles' );

The key here is that get_stylesheet_uri() retrieves the URL of the active stylesheet. If you are using WP-LESS, the plugin usually generates a .css file from your .less source. You should enqueue that generated CSS file, not the raw .less file directly via wp_enqueue_style, unless the plugin specifically exposes a hook for the uncompiled version (which is rare and generally not recommended for production).

One common pitfall developers face when moving to wp_enqueue_style() is handling dependencies. In your example, you included 'blueprint' as a dependency array. This tells WordPress: "Load mytheme-style only after Blueprint has loaded." If the URL of the Blueprint stylesheet returns false or if the file doesn't exist on your server, wp_enqueue_style() will throw an error and halt execution. Always verify that third-party libraries are correctly registered before declaring them as dependencies in your own theme functions.

Another critical detail is versioning. WordPress allows you to pass a version string as the fourth argument to wp_enqueue_style(). This is essential for browser caching strategies. If you change your CSS but forget to bump this version number, browsers might continue serving the old cached file, resulting in broken layouts or missing styles.

wp_enqueue_style( 'mytheme-style', get_stylesheet_uri(), array(), '1.0.2' );

When working with LESS specifically, ensure you are enqueueing the compiled output. The WP-LESS plugin handles the compilation step, but it expects your theme to load the resulting CSS via standard WordPress mechanisms. Replacing your static <link> tag entirely is unnecessary if you use wp_enqueue_style() correctly; rather, the function call replaces the logic that determines which file is linked and when it is loaded.

If you are transitioning from a static setup to a dynamic one, ensure you don't leave both methods active simultaneously. Having a hardcoded <link> tag pointing to a compiled file while also calling wp_enqueue_style() for the same asset can lead to duplicate stylesheets being rendered on every page load, bloating your network requests and potentially causing specificity issues in your CSS.

For advanced scenarios involving multiple breakpoints or conditional loading, you might need to enqueue different LESS files based on device width. In those cases, WP-LESS plugins often provide hooks that allow you to queue specific compiled assets for mobile versus desktop views without manual file manipulation.

Our network