添加 header.php 文件后,Wordpress 中的 style.css 不起作用

问题描述:

如果我将一个简单的header.php"文件添加到我的主题文件夹,我的 style.css 就会停止工作,如果我删除header.php",它会再次开始工作.

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

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();
?>

谢谢!

你的header.php和index.php都不错,只需要替换functions.php文件中的下面一行:

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');

有了这个:

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

然后一切都很好.