wp enqueue 1

wp enqueue

/** 
 *   Enqueue your theme styles and scripts in functions.php
 *   use time() instead of a proper versioning to avoid caching when developing
 */
function my_theme_enqueue_scripts() {
    wp_enqueue_style( 'default-style', get_stylesheet_uri(), [], '1.0.0', 'all' ); //default styles.css
    wp_enqueue_style( 'main-style', get_stylesheet_directory_uri() . '/assets/css/main.min.css', [], time(), 'all' );
    wp_enqueue_script( 'main-script', get_stylesheet_directory_uri() . '/assets/js/main.min.js', [], time(), false );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_scripts' );

Here is what the above code is Doing:
1. wp_enqueue_style() is a WordPress function that allows you to enqueue a stylesheet.
2. get_stylesheet_uri() is a WordPress function that returns the URI of the current theme’s stylesheet.
3. get_stylesheet_directory_uri() is a WordPress function that returns the URI of the current theme’s directory.
4. wp_enqueue_script() is a WordPress function that allows you to enqueue a script.
5. time() is a PHP function that returns the current Unix timestamp.
6. add_action() is a WordPress function that allows you to add a function to a specific WordPress action.

Similar Posts