我为主题定制创建了一个子主题,wordpress正在识别这个主题并加载它。
有一些变化没有通过,我注意到css选择器,看看是否遗漏了什么东西,然后我发现了一个主题,有人建议检查加载顺序,并且非常正确,父样式表的小型化样式表在子主题样式表之后加载。
如果我稍微欺骗代码,将父样式(而不是常规样式)排队,并删除/匹配子样式的版本号,小型化css以前会加载,但css更改仍然不会覆盖。
如果我不更改子版本的版本号,则父版本的缩小,匹配子版本的版本号。
下面是我要解释的所有代码和屏幕截图。
儿童的functions.php -主题:
function my_theme_enqueue_styles() {
$parent_style = 'parent-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.min.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' );儿童的style.css -主题:
/*!
Theme Name: Customify Child
Theme URI: https://wpcustomify.com
Author: JNK XI
Author URI: https://
Description: Customify Child Theme
Template: customify
Version: 0.1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: customify-child
Domain Path: /languages
Tags: custom-background, custom-logo, custom-menu, custom-logo, featured-images, flexible-header, footer-widgets, full-width-template, sticky-post, theme-options, threaded-comments, translation-ready, one-column, two-columns, three-columns, left-sidebar, right-sidebar, e-commerce, blog
*/控制台Printscreen如果子主题样式表的版本与父版本的不同

控制台Printscreen如果子主题样式表的版本与父版本的匹配

如果有什么不清楚的地方请告诉我。
如能提供任何帮助,将不胜感激。
发布于 2018-06-22 02:03:01
代码中的$parent_style变量真的是$parent_style = 'parent-style';吗?
如果是的话,那就是你的问题。看起来您使用的是这里是法典中的例子,这很好,但是您可能忽略了下面这个片段:
其中,
parent-style在注册样式表时与父主题中使用的$handle相同。例如,如果父主题是二十五个,通过查看其functions.php中的wp_enqueue_style()调用,您可以看到它在那里使用的标记是'twentyfifteen-style'。在子代码中,将'parent-style'实例替换为'twentyfifteen-style'
在Customify主题中,"$handle“是在PHP函数中构建的,这使它有点混乱。在查看主题代码之后,看起来样式表的句柄是'customify-style'。
有了这些知识,试着取代
$parent_style = 'parent-style';
通过以下方式:
$parent_style = 'customify-style';
免责声明:我只浏览了主题的代码,样式的句柄可能与我在这里编写的不同。如果是这样的话,您应该尝试找到主题的样式表注册或排队的实际名称。
https://wordpress.stackexchange.com/questions/306643
复制相似问题