I'm creating for the first time a theme from scratch.

It's not a child theme

In theme's function.php file I'm doing

add_action( 'wp_enqueue_scripts', function() {

  wp_enqueue_style( 'style', get_stylesheet_uri()); 

But the style.css file is not included in the served html.

Is there something I must do to 'force' inclusion of my theme's CSSes ?

In the index.php I tried to print get_stylesheet_uri() and I got the full URL of my css: http://my.domain.it/wp-content/themes/real/style.css

For reference, this is my theme's index.php

<!-- Inizio di INDEX.PHP -->


<!-- Index.php, dopo get_header(); !-->

<DIV id="container">

  <div id="row1">
    Riga 1

  <div id="row2">
    Riga 2

</DIV> <?php //  id="main_container" ?>

<!-- Index.php, prima di get_footer(); !-->


<!-- Fine di INDEX.PHP -->

I'm calling get_header() and my header file is included

This is Header.php

<!DOCTYPE html>

      <?php bloginfo( 'name' ); ?>

    <meta name="description" content=" <?php bloginfo( 'description' ); ?>  ">


<!-- Fine di HEADER.PHP -->


As stated here: https://codex.wordpress.org/Function_Reference/wp_head.

Put this template tag immediately before tag in a theme template (ex. header.php, index.php).

So I added

<?php wp_head() ?>

just before </HEAD and now it works.

  • 1
    ohh, so you were not including header in your page? Feb 24 '17 at 12:44
  • I was including my headers, but not WP's header :) . It's my first steps with a scratch theme. It's not very well documented this steps, or I've not seen.
    – realtebo
    Feb 24 '17 at 12:48

let's try this way:

// Recommended way to include parent theme styles.
//  (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme)

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
  • It's a simplet CODE styling difference. I use anonymous function. You not. The code is the same. Also, i'm not doing a child theme. I started from scratch. From empty index.php and empty style.css. I added some other hooks to my functions.php file and all of theme are working well. Just this is not working.
    – realtebo
    Feb 24 '17 at 12:32

use <?php wp_head() ?> before </head> in header.php and then use this codes in function.php :

function my_style() {
    wp_enqueue_style(  'style', get_stylesheet_uri()); 

add_action( 'wp_enqueue_scripts', 'my_style' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.