style.css in Wordpress doesn't work after addi

2019-08-13 22:47发布

问题:

If I add a simple "header.php" file to my theme folder, my style.css simply stops working, if I delete the "header.php", it starts working again.

How can I resolve this?

Here's the simple code of my files:

index.php:

<?php

get_header(); 

?>
 <p>TEST</p>

 <button id="btn">jQuery Test</button>

style.css:

    /*
Theme Name: Thème Dias
Description: Mon thème
*/

    p{
    color:green;
    font-size:100px;
    }

functions.php

<?php
//Definir le répertoire du thème
define("THEME_DIR", get_template_directory_uri());

//Enlever le générateur de tags meta pour la sécurité (les gents ne peuvent pas voir quelle version WP)
remove_action('wp_head', 'wp_generator');


// ENQUEUE STYLES
function enqueue_styles() {

    /* Main CSS */
    wp_register_style( 'main-css', THEME_DIR . '/style.css', array(), '1', 'false');
    wp_enqueue_style( 'main-css' );

}
add_action( 'wp_enqueue_scripts', 'enqueue_styles' );


// ENQUEUE SCRIPTS
function enqueue_scripts() {
    wp_enqueue_script( 'jquery' );

    /* jQuery Custom Scripts */
    wp_register_script( 'jquery-custom', THEME_DIR . '/js/custom.js', array('jquery'), '1.0.0', 'true');
    wp_enqueue_script( 'jquery-custom' );

}
add_action( 'wp_enqueue_scripts', 'enqueue_scripts' );
?>

header.php

<?php
wp_head();
?>

Thank you!

回答1:

your header.php and index.php are all good, you just need to replace the following line of your functions.php file:

wp_register_style( 'main-css', THEME_DIR . '/style.css', array(), '1', 'false');

with this one:

wp_register_style( 'main-css', THEME_DIR . '/style.css', array(), '1', 'all');

and then it is all good.