How to enqueue custom CSS to WordPress functions.php

Last updated on

Open functions.php in your WordPress themes folder, usually located in /wp-content/themes/{theme_name}/

Add the following code to the end of functions.php

function custom_styles() {
	wp_enqueue_style( 'custom-style', get_template_directory_uri() . '/css/style.css' );
}
add_action( 'wp_enqueue_scripts', 'custom_styles' );

Ensure that your css file is uploaded to your theme’s CSS folder, usually located in /wp-content/themes/{theme_name}/css/ or /wp-content/themes/{theme_name}/assets/css/

wp-admin custom style

To enquene a custom css file for wp-admin backend, add the following code to the end of functions.php

function load_custom_wp_admin_style(){
    wp_register_style( 'custom_wp_admin_css', get_bloginfo('stylesheet_directory') . '/admin-style.css', false, '1.0.0' );
    wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action('admin_enqueue_scripts', 'load_custom_wp_admin_style');

 

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

Leave a reply

Your email address will not be published. Required fields are marked *