我正在尝试在网站上添加一个儿童主题,我创建了一个名为mythemename child的文件夹,我创建了样式。包含以下信息的css文件:
/*
Theme Name: Mizrahi-child
Theme URI: http://www.templatemonster.com/wordpress-themes
Description: Your theme description.
Author: Matteo Schiatti
Author URI: http://www.templatemonster.com/
Template: mizrahi
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: mizrahi
Tags: one-column, two-columns, three-columns, left-sidebar, right-sidebar, custom-background, custom-colors, custom-menu, featured-images, post-formats, sticky-post, theme-options, threaded-comments, translation-ready
*/
在我创建函数之后。包含以下内容的php文件:
<?php
add_action( \'wp_enqueue_scripts\', \'enqueue_parent_styles\' );
function enqueue_parent_styles() {
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/style.css\' );
}
我可以在后台看到子主题,但当我激活它时,网站会丢失所有css。
我不明白为什么,我也尝试了样式上的@import方法。css文件,但没有:
@导入url(“../Twenty15/style.css”);
我在函数中添加了此代码。php:
<?php
function enqueue_parent_styles() {
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/font-awesome.min.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/magnific-popup.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/magnific-popup.min.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/material-icons.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/material-icons.min.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/slider-pro.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/slider-pro.min.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/style.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/swiper.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/swiper.min.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/plugins/booked.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/plugins/builder.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/plugins/restaurant-menu.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/site/buttons.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/site/elements.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/site/footer.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/site/forms.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/site/header.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/site/menus.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/site/misc.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/site/navigation.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/site/post.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/site/social.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/widgets/about.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/widgets/custom-post.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/widgets/instagram.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/widgets/subscribe.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/css/dynamic/widgets/widget-default.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/rtl.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/style.css\' );
}
add_action( \'wp_enqueue_scripts\', \'enqueue_parent_styles\' );
SO网友:Marcelo Henriques Cortez
正如我在报告中所说comments, CSS的名称必须是唯一的。您将每个CSS命名为“父样式”。每个都必须有不同的名称。
像这样:
wp_enqueue_style( \'parent-style1\', get_template_directory_uri().\'/style1.css\' );
wp_enqueue_style( \'parent-style2\', get_template_directory_uri().\'/style2.css\' );
代码
function enqueue_parent_styles() {
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/style.css\' );
}
如果主题具有
ALL 主屏幕内的it样式
style.css. 在大多数情况下,这是行不通的,因为模板在另一个目录中有更多的CSS。
您可能需要执行以下操作:
function enqueue_parent_styles() {
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/style.css\' );
wp_enqueue_style( \'parent-style\', get_template_directory_uri().\'/assets/another-style.css\' );
}
如果您需要拥有自己的CSS文件,则需要将其排队
AFTER 家长
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\')
);
首先排列次要样式,然后排列主要样式
AFTER 他们
确保调用了“add\\u操作”AFTER 创建函数。