添加 header.php 文件后,Wordpress 中的 style.css 不起作用 [英] style.css in Wordpress doesn't work after adding header.php file

查看:31
本文介绍了添加 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');

然后一切都很好.

这篇关于添加 header.php 文件后,Wordpress 中的 style.css 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆