如何在wordpress中的fonts.php之后加载style.css?

时间:2015-06-23 19:17:49

标签: php css wordpress override declare

我正在 WordPress 中本地开发一个网站,然后将其上传到临时开发服务器,以定期向管理层显示我的进度。

问题: 当我将所有内容上传到服务器时,我注意到我的style.css中的样式被fonts.php中的样式覆盖。这是我第一次使用Wordpress平台。我不知道为什么,但当我在本地托管它时,情况并非如此。如图所示,fonts.php在style.css之后声明。 图片:enter image description here

我尝试了什么: 我正在深入研究wordpress文件,找到一种方法先声明fonts.php然后再使用style.css,以便style.css覆盖fonts.php。我在wp-includes / theme.php中找到了这个文件,在那里我发现了style.css被声明但找不到fonts.php。这是一个死胡同。

有人知道怎么做吗?

3 个答案:

答案 0 :(得分:1)

// Load the theme stylesheets
function theme_styles()  
{ 

    // Example of loading a jQuery slideshow plugin just on the homepage
    wp_register_style( 'flexslider', get_template_directory_uri() . '/css/flexslider.css' );

    // Load all of the styles that need to appear on all pages
    wp_enqueue_style( 'main', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'custom', get_template_directory_uri() . '/css/custom.css' );

    // Conditionally load the FlexSlider CSS on the homepage
    if(is_page('home')) {
        wp_enqueue_style('flexslider');
    }

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

答案 1 :(得分:1)

让我们举一个例子,使用wp_enqueue_style()

在wordpress中导入Bootstrap CSS样式表

首先,您需要插入

`<?php wp_head(); ?>` 

所以你的主题可以使用使用wp_head()钩子的过滤器和钩子。因此,可以轻松调用任何主题添加。

确保你有wp_head();在主题的head部分之间,在header.php文件中。

然后在主题目录中创建一个新文件functions.php,其中index.php也存在。在functions.php中,我们将创建一个新函数,然后使用wp_register_script函数注册样式,然后使用wp_enqueue_style函数调用我们的样式。

这是我们将用于在Bootstrap样式表中调用的代码。

`<?php
function add_stylesheet() {
wp_register_style('bootstrap.min',get_template_directory_uri() . 
'/css/bootstrap.min.css');
wp_enqueue_style( 'bootstrap.min' );
}
add_action( 'wp_enqueue_scripts', 'add_stylesheet' );
?>`

那么上面的代码是做什么的?

add_stylesheet()是我们创建的函数的名称,您可以将它命名为任何您想要的名称。

然后,我们通过WordPress函数wp_register_style注册了样式表。它接受5个不同的参数

`$handle, $src, $deps, $ver, and $in_footer`

注册完我们的风格后,我们可以使用WordPress函数wp_enqueue_style调用它。就是这样,这个方法起初可能看起来很复杂,但这是在WordPress中调用样式表的首选方法。

答案 2 :(得分:1)

感谢Susheel的发帖。如果我必须在外部添加一个css文件但是没有解决我的问题,这是有帮助的,这确保在此之前加载fonts.php。

我发现了一个简单的解决方案。 我在adaptive.css文件中移动了我想要覆盖的所有css,它总是在fonts.php文件之后加载。