【问题标题】:enqueuing a minified CSS into Wordpress将缩小的 CSS 排队到 Wordpress
【发布时间】:2017-10-05 10:36:32
【问题描述】:

我目前正在使用带有 wordpress 主题的 style.css(显然),当我编辑它时,我也在保存文件时缩小文件。这会生成另一个文件 style.min.css,

现在,我已经在 functions.php 文件中加入了 style.css,但我需要将它换成 .min.css 吗?

或者它会自动加载 .min.css 文件吗? (因此使用缩小文件使其加载速度更快)。

谢谢, 阿兹

【问题讨论】:

  • 不行,需要手动操作,没有自动交换过程
  • 您是否在 style.css 中获取了更新后的 css?如果是,则无需添加 min.css,如果不是,则必须单独入队。

标签: css wordpress


【解决方案1】:

style.css 是 WP 的必需文件,为 functions.php。没有可以换。无论您使用什么来缩小(SASS 或任务运行器)都需要输出到 style.css。记得加“!”到样式 cmets 以便它们不会被缩小。即

/*!
Theme Name: theme_name
Theme URI: http://theme_name.com/
Author: theme_name
Author URI: http://theme_name.com/
Description: WordPress Theme for theme_name
*/

或者您可以简单地将 min.css 文件加入到 functions.php 文件中,并将 style.css 与注释部分一起保留,而无需 css 代码。

function new_theme_scripts() {

    wp_enqueue_style ( 

    wp_enqueue_style ( 'text-domain-new-css', get_template_directory_uri() . '/css/style.css' );

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

【讨论】:

    猜你喜欢
    • 2015-06-12
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    • 1970-01-01
    • 1970-01-01
    • 2016-09-04
    相关资源
    最近更新 更多