首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不使用Wordpress子主题css

不使用Wordpress子主题css
EN

Stack Overflow用户
提问于 2018-12-07 14:02:38
回答 1查看 132关注 0票数 2

我有一个Wordpress网站,在那里,孩子的主题被激活。看起来一切正常,除了样式表。不包括CSS文件。

在子主题中的function.php文件中:

代码语言:javascript
复制
function enqueue_child_styles() {
    wp_enqueue_style('child-theme', get_stylesheet_directory_uri() .'/style.css', array('parent-theme'));

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

style.css文件位于子主题的根文件夹中:

但风格并没有反映在我的网站本身。

我的孩子主题CSS:

代码语言:javascript
复制
/*
Theme Name: Vitrine Child
Theme URI: http://themeforest.net/user/Epicomedia
Template: vitrine
Author: EpicoMedia
Author URI: http://www.Epicomedia.com
Description: WooCommerce WordPress Theme
Tags: two-columns,three-columns,left-sidebar,right-sidebar,custom-background,custom-header,custom-menu,editor-style,featured-images,flexible-header,full-width-template,microformats,post-formats,sticky-post,theme-options,translation-ready,accessibility-ready
Version: 1.0.1498974811
Updated: 2017-07-02 05:53:31

*/

/* Write your styles here */
/* Cookiebot */
a#CybotCookiebotDialogBodyLevelButtonAccept {
    background: #E5002F !important;
    border: none !important;
}

/* WPCF7 form submit button */
.wpcf7-form-control.wpcf7-submit {
    border-color: black;
    color: black;
}

儿童主题的function.php:

代码语言:javascript
复制
<?php
require_once dirname( __FILE__ ) . '/widgets/bln-widget-functions.php';

// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

function example_enqueue_styles() {
    // enqueue child styles
    wp_enqueue_style('child-theme', get_stylesheet_directory_uri() .'/style.css', array('parent-theme'));
}

add_action('wp_enqueue_scripts', 'example_enqueue_styles');
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-07 14:05:07

翻阅法典:Themes

子主题中的style.css需要一个特定的注释头:

“法典”中的规定如下:

代码语言:javascript
复制
/*
 Theme Name:   Twenty Fifteen Child
 Theme URI:    http://example.com/twenty-fifteen-child/
 Description:  Twenty Fifteen Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentyfifteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twenty-fifteen-child
*/

有几件事要注意:

您需要将示例文本替换为与主题相关的详细信息。模板行对应于父主题的目录名。

示例中的父主题是二十五个主题,因此模板将是二十五个。您可能使用的是不同的主题,因此相应地进行调整。

更新:

enqueue父主题和子主题(只有当其中包含css时才需要子css ):

只是家长:

代码语言:javascript
复制
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}
?>

父母和子女:

代码语言:javascript
复制
<?php
function my_theme_enqueue_styles() {

    $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.

    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 ),
        wp_get_theme()->get('Version')
    );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53671114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档