我有一个激活了儿童主题的Wordpress网站。除样式表外,其他一切似乎都正常运行。不包含CSS文件。
在子主题的function.php文件中:
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:
/*
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:
<?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');
答案 0 :(得分:1)
浏览法典:https://codex.wordpress.org/Child_Themes
您的子主题中的style.css
需要特定的注释标题:
食品法典中的典范是:
/*
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
*/
需要注意的几件事:
您将需要用与主题相关的详细信息替换示例文本。 模板行对应于父主题的目录名称。
该示例中的父主题是25个主题,因此模板将是25个。您可能正在使用其他主题,因此请进行相应调整。
更新:
enqueue
既有父主题又有子主题(如果您有css,则仅需要子css):
亲父:
<?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' );
}
?>
父母与子女:
<?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' );
?>