Adding a custom css file to your wordpress theme is very easy. Adding a custom css file is very useful especially if you are not using a custom theme.
By using a custom css file, the changes you do to your website won’t be lost if an update in your theme occurs.
How to add a wordpress custom css file
First we have to add some code to the theme’s functions.php file. Open the file and add the below:
add_action(‘wp_enqueue_scripts’, ‘your_function_name’);
(This uses the add action hook, hooking into the wp_enqueue_scripts action.)
Then, you will need to add the function to your functions.php file that will utilize the WordPress function wp_enqueue_style:
function your_function_name() {
wp_enqueue_style(‘my-script-slug’, get_stylesheet_directory_uri() . ‘/your_style.css’);
}
Please note the use of get_stylesheet_directory_uri() – this gets the proper stylesheet directory for your theme.