Skip to main content
Login Join
Snippet · PHP

Loading CSS and JavaScript

Shared by Mukesh Gujjar · July 6, 2026 · @wp_enqueue_scripts

28 views
1 upvote
Back to Snippets

This is the standard, safe way to add stylesheets and scripts to your front-end.

/**
 * Enqueue theme styles and scripts.
 */
function my_theme_enqueue_assets() {
    // Load a CSS file
    wp_enqueue_style( 'my-custom-style', get_stylesheet_directory_uri() . '/style.css', array(), '1.0.0' );
    
    // Load a JS file
    wp_enqueue_script( 'my-custom-script', get_stylesheet_directory_uri() . '/js/main.js', array('jquery'), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_assets' );
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments