How to add the main style.css to my index.php?

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 -->

<?php 
  get_header();
?>

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

<DIV id="container">

  <div id="row1">
    Riga 1
  </div>

  <div id="row2">
    Riga 2
  </div>

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

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

<?php 
  get_footer();
?>

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

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

This is Header.php

<!DOCTYPE html>
<html>
  <head>

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

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

  </head>
  <body>

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

3 Answers
3

Found:

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.

Leave a Comment