How to enqueue a styles.css file in a WordPress theme

To include a styles.css file in your WordPress theme, you need to enqueue the stylesheet using the wp_enqueue_style() function. You should do this in your theme’s functions.php file. Here’s how:

  1. In your WordPress admin dashboard, go to “Appearance” > “Theme Editor.”
  2. In the right sidebar, locate and click on the “functions.php” file.
  3. Add the following code snippet at the end of the file:
function my_theme_enqueue_styles() {
    wp_enqueue_style('my-theme-style', get_stylesheet_uri());
add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles');

This code snippet creates a function called my_theme_enqueue_styles(), which enqueues your theme’s style.css file using the wp_enqueue_style() function. The get_stylesheet_uri() function retrieves the URL of the active theme’s style.css file.

  1. Click “Update File” to save the changes.

Now, your theme’s style.css file will be properly enqueued and loaded on your WordPress site.

Note: Make sure your theme has a style.css file in its root directory. If it doesn’t, create one and add your custom CSS styles there. The style.css file is also used to store theme information in its header, which is required for the theme to be recognized by WordPress.

Leave a Reply

Your email address will not be published. Required fields are marked *