html - 添加 style.css 后 Wordpress 不工作

标签 html css wordpress

一段时间以来,我一直在努力寻找解决方案,但运气不佳...... 我正忙于根据 this article 为 WordPress 制作自定义主题. 像 get_header() 这样的 html 和 php 钩子(Hook)工作得很好,但是当我尝试添加 style.css 它就不起作用了,“演示主题”被卡住了在加载时。但是,当我删除它时,它可以完美运行,但未加载 style.css 文件中的 css。 这些是我想加载到页面中的 css 文件。

<link rel="stylesheet" href="http://www.website.com/wp-content/themes/canvas/css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="http://www.website.com/wp-content/themes/canvas/style.css" type="text/css" />
<link rel="stylesheet" href="http://www.website.com/wp-content/themes/canvas/css/dark.css" type="text/css" />
<link rel="stylesheet" href="http://www.website.com/wp-content/themes/canvas/css/font-icons.css" type="text/css" />
<link rel="stylesheet" href="http://www.website.com/wp-content/themes/canvas/css/animate.css" type="text/css" />
<link rel="stylesheet" href="http://www.website.com/wp-content/themes/canvas/css/magnific-popup.css" type="text/css" />
<link rel="stylesheet" href="http://www.website.com/wp-content/themes/canvas/css/responsive.css" type="text/css" />

如何将所有这些 css 文件正确加载到 WordPress 页面中。 谢谢! 我目前正在使用以下代码

    define("THEME_DIR", get_template_directory_uri());
/*--- REMOVE GENERATOR META TAG ---*/
remove_action('wp_head', 'wp_generator');

// ENQUEUE STYLES

function enqueue_styles() {

    /** REGISTER css**/
    wp_register_style( 'bootstrap', THEME_DIR . '/css/bootstrap.css', array(), '1', 'all' );
    wp_register_style( 'dark', THEME_DIR . '/css/dark.css', array(), '1', 'all' );
    wp_register_style( 'font-icons', THEME_DIR . '/css/font-icons.css', array(), '1', 'all' );
    wp_register_style( 'animate', THEME_DIR . '/css/animate.css', array(), '1', 'all' );
    wp_register_style( 'magnific-popup', THEME_DIR . '/css/magnific-popup.css', array(), '1', 'all' );
    wp_register_style( 'responsive', THEME_DIR . '/css/responsive.css', array(), '1', 'all' );
    //wp_register_style( 'style', THEME_DIR . '/style.css', array(), '1', 'all' );

    /** ENQUEUE css**/
    wp_enqueue_style( 'bootstrap' );
    wp_enqueue_style( 'dark' );
    wp_enqueue_style( 'font-icons' );
    wp_enqueue_style( 'animate' );
    wp_enqueue_style( 'magnific-popup' );   
    wp_enqueue_style( 'responsive' );
    //wp_enqueue_style( 'style' );
}
add_action( 'wp_enqueue_scripts', 'enqueue_styles' );

// ENQUEUE SCRIPTS

function enqueue_scripts() {

    wp_register_script( 'html5-shim', 'http://html5shim.googlecode.com/svn/trunk/html5.js', array( 'jquery' ), '1', false );
    wp_enqueue_script( 'html5-shim' );


    wp_register_script( 'custom-script', THEME_DIR . '/js_path/customscript.js', array( 'jquery' ), '1', false );
    wp_enqueue_script( 'custom-script' );

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

但这不起作用...我还检查了我的头文件中是否存在 wp_head() 并且所有 php 都在工作??? 只要我添加 style.css 它就会卡在加载中 enter image description here

enter image description here

最佳答案

通常,为样式表句柄使用唯一的名称是个好主意(参见 reference )。我无法重新创建错误,但您可以尝试更改

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

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

wp_enqueue_style( 'style' );

wp_enqueue_style( 'unique-name-style' );

关于html - 添加 style.css 后 Wordpress 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35037813/

相关文章:

html - 如何悬停元素样式本身和另一个元素

html - CSS 内容属性对 SEO 友好吗?

html - 使用 CSS 将文本分成行

javascript - 加载时增量 JQuery 函数

html - 页面居中对齐按钮

javascript - 添加新文本时如何保持文本区域文本静态

用于在穿孔卡片上打印的 CSS

html - 此 css 不适用于页脚元素

html - 上传前使用 md5 检查的多个文件上传

php - 如何从 WordPress 中的另一个数据库获取帖子元