# Load a custom.css File From the Theme

> Enqueues custom.css from the active (child) theme folder if it exists, with a version based on its modification time to bust caches.

- Type: PHP
- Runs: Run everywhere
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: developer, css, theme, enqueue
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/load-custom-stylesheet/

## Code

```php
add_action( 'wp_enqueue_scripts', function () {
    $path = get_stylesheet_directory() . '/custom.css';

    if ( file_exists( $path ) ) {
        wp_enqueue_style( 'wpide-custom-css', get_stylesheet_directory_uri() . '/custom.css', array(), (string) filemtime( $path ) );
    }
}, 20 );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Load a custom.css File From the Theme" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
