【问题标题】:Wordpress Custom CSS added twice?Wordpress 自定义 CSS 添加了两次?
【发布时间】:2016-07-23 07:44:50
【问题描述】:

不是 100% 确定这个问题对于堆栈是否合法,但它不属于 Meta 并且确实涉及一些代码,我不认为它是主观的 - 应该有答案...

我有一个使用 The7 主题的新 wordpress 网站,当然,我使用“One Click Child Theme”插件创建了一个子主题。

一切正常,我在其中放了一些自定义 css 来调整导航并且它会调整,但是当我在 chrome 中查看 Inspector 时,我看到我的自定义 css 列出了两次!有人知道为什么吗?我的子样式表中没有任何额外的import 语句,即使有,此代码也不在父样式表中。子样式表是否被加载了两次?

我知道很多网络代码,但对使用 Wordpress 还是很陌生。这是正常行为吗?

这是我的整个子样式表:

/*
Theme Name:     the7 Child
Description:    
Author:         chris@sqlfocus.com
Template:       dt-the7

(optional values you can add: Theme URI, Author URI, Version, License, License URI, Tags, Text Domain)
*/

ul.main-nav {
    padding-left: 100px;
    padding-right: 100px;   
    -webkit-padding-start: 100px;
    -webkit-padding-end: 100px;
}

这是检查员:

functions.php:

<?php
//
// Recommended way to include parent theme styles.
//  (Please see http://codex.wordpress.org/Child_Themes#How_to_Create_a_Child_Theme)
//  
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array('parent-style')
    );
}
//
// Your code goes below
//

【问题讨论】:

  • 列出两次是什么意思?在呈现的规则中还是您看到两次 css 链接?
  • 用我的检查员的图片更新了问题
  • 共享functions.php 文件中的代码,您可以在其中将子主题的样式表排入队列
  • 共享。看起来它只加载一次。
  • [crickets] 我不敢相信这超出了 SO 上每个人的知识范围

标签: css wordpress themes


【解决方案1】:

我在使用 Enfold 主题时遇到了完全相同的问题,而且我以前在使用其他主题时也遇到过。

我研究了一个页面的 HTML 输出,发现主题是自动包含我的样式表的。这是出乎意料的,因此是不可取的,因为不可预测性是不可取的——并非所有主题都这样做。

解决办法?有点好笑……但我只是……

removed my own reference from functions.php and let the parent theme auto-include it for me

悲伤但真实......

【讨论】:

    猜你喜欢
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 2014-08-16
    • 2020-09-22
    相关资源
    最近更新 更多