WordPress-CSS导入对我不起作用

1 css php wordpress themes

我是WordPress n00b。我似乎无法将简单的CSS导入到我的页面中。

这是我尝试过的:

index.php

<link href="style.css" rel="stylesheet" type="text/css">
Run Code Online (Sandbox Code Playgroud)

style.css

/* External */
@import: url('http://fonts.googleapis.com/css?family=Varela');
@import: url('https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css');

/* Internal */
@import: url('css/bootstrap.css');
@import: url('css/custom-styles.css');
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

index.php:

<link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet" type="text/css">
Run Code Online (Sandbox Code Playgroud)

只是为了确保这一点:

<link href="<?php bloginfo('style.css'); ?>" rel="stylesheet" type="text/css">
Run Code Online (Sandbox Code Playgroud)

我已经完成了研究,但是除了上面已经尝试过的以外,我找不到其他东西。因此,如果这是重复的话,我表示歉意。

编辑:

这在index.php中的WordPress中不起作用:

<link href="style.css" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=Varela" rel="stylesheet" type="text/css">
<link href="css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css">
<link href="css/custom-styles.css" rel="stylesheet" type="text/css">
Run Code Online (Sandbox Code Playgroud)

Tal*_* me 5

您对Wordpress的处理方式不正确。您应该加入样式表。以下内容应该放在您的functions.php文件中。

function enqueue_styles() {
    wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/style.css');
}
Run Code Online (Sandbox Code Playgroud)

如果您在示例中使用硬编码链接,则应将其添加到header.php中,但是,这是一种不好的做法,因为Wordpress具有处理依赖关系和冲突的独特方法。

查看法典

另外,正如已经提到的,使用@import加载多个样式表通常是一种不好的做法。您可以使用enqueue加载所有这些脚本,只需确保最后需要加载所需的脚本即可:

    function enqueue_styles() {
 wp_enqueue_style( 'stylesheet', 'netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css');
 wp_enqueue_style( 'stylesheet', 'http://fonts.googleapis.com/css?family=Varela');
 wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css', array() );
 wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/style.css');
 wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/css/custom-styles.css');
    }
Run Code Online (Sandbox Code Playgroud)

然后像这样钩住它:

add_action( 'wp_enqueue_scripts', 'enqueue_styles' );
Run Code Online (Sandbox Code Playgroud)