enqueue css wordpress code example
Example 1: wp enqueue styles
function my_theme_enqueue_scripts() {
wp_enqueue_style( 'default-style', get_stylesheet_uri(), [], '1.0.0', 'all' );
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' );
Example 2: enqueue wordpress
function wpdocs_theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() );
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
Example 3: how to add css file in wordpress
wp_enqueue_style( 'style', get_stylesheet_uri() );
Example 4: wp enqueue style
wp_enqueue_style( 'my-style', get_template_directory_uri() . '/css/my-style.css', false, '1.0', 'all' );
wp_enqueue_style( 'my-style', get_stylesheet_directory_uri() . '/css/my-style.css', false, '1.0', 'all' );
wp_enqueue_style( 'my-style', plugins_url( '/css/my-style.css', __FILE__ ), false,