简体   繁体   中英

style.css in Wordpress doesn't work after adding header.php file

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM