Learn Computer Academy

WordPress Enqueue Snippet Generator

Add style and script rows, set the details, get a real, correctly-wrapped wp_enqueue_style() / wp_enqueue_script() block back.

Enqueuing Assets lesson

Function Name

Theme Directory Function

get_template_directory_uri() always points at the parent theme — use it even inside a child theme unless you specifically mean the child's own files (get_stylesheet_directory_uri()).

Assets

style
Version

Busts the browser cache automatically every time you save the file — no more manually bumping a version number.

script
Version

Busts the browser cache automatically every time you save the file — no more manually bumping a version number.

Generated PHP

function mytheme_enqueue_assets() {
    $uri = get_template_directory_uri();
    $dir = get_template_directory();

    wp_enqueue_style( 'mytheme-style', $uri . '/css/style.css', array(), filemtime( $dir . '/css/style.css' ) );
    wp_enqueue_script( 'mytheme-main', $uri . '/js/main.js', array( 'jquery' ), filemtime( $dir . '/js/main.js' ), true );
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_assets' );