functions.php not adding css to website?

So I went through the forum to find a solution before I post a question, however I have yet to find it. I’m new to wordpress and I’m having a lot of fun learning on how to build my own website. However I am unable to add my css to my website this the code I have below.

functions.php

<?php 
function fearnothing_script_enqueue(){
    wp_enqueue_style("style",  get_stylesheet_uri()."css/
        fearnothing.css",false, 'all');


}

add_action('wp_enqueue_scripts', 'fearnothing_script_enqueue');

header.php

<!DOCTYPE html>
<html>
<head>
    <title>lonely spaceship</title>
    <?php wp_head(); ?>
</head>
<body>

footer.php

        <footer>
        <p></p>
    </footer>
    <?php wp_footer(); ?>
</body>

fearnothing.css

 html, body {
    margin: 0;
    color: #91f213;
    background-color:black;
    font: sans-serif;
}

body{
    padding: 20px;
}

h1{
    color: yellow;
}

3 Answers
3

I don’t know if you try to add a css file in your theme or plugin. I will provide both examples. Use wp_enqueue_style in combination with get_theme_file_uri to enqueu a stylesheet in your theme directory.

For a theme, see example

function add_styles() {
    wp_enqueue_style( 'fontawesome-style', get_theme_file_uri( '/assets/css/all.css' ), array(), null );
}
add_action( 'wp_enqueue_scripts', 'add_styles' );

For a plugin, see example

function add_styles() {
    wp_enqueue_style( 'example-styles-plugin', plugins_url('/assets/css/admin.css', __FILE__), array(), null );
}
add_action( 'wp_enqueue_scripts', 'add_styles' );

For both, add an external URL:

function add_styles() {
    // Add Google Fonts
    wp_enqueue_style('google_fonts', 'https://fonts.googleapis.com/css?family=Poppins:300,500,700', array(), null );
}
add_action( 'wp_enqueue_scripts', 'add_styles' );

Leave a Comment