@dalbaeb的评论最终导致了深入的讨论和可行的解决方案。非常感谢!
我相信加载我的子主题CSS的原因'ver=<parent-theme-version>
是因为我在子主题 1:1 上遵循了WP Codex。我functions.php
包含:
add_action('wp_enqueue_scripts', 'theme_enqueue_styles');
function theme_enqueue_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
}
我最终使用的代码最初是在https://wordpress.stackexchange.com/a/182023/30783中提到的,但是Internet上的许多站点都将其复制粘贴(未给予适当的信誉)。
// Making sure your child theme has an independent version and can bust caches: https://wordpress.stackexchange.com/a/182023/30783
// Filter get_stylesheet_uri() to return the parent theme's stylesheet
add_filter('stylesheet_uri', 'use_parent_theme_stylesheet');
// Enqueue this theme's scripts and styles (after parent theme)
add_action('wp_enqueue_scripts', 'my_theme_styles', 20);
function use_parent_theme_stylesheet()
{
// Use the parent theme's stylesheet
return get_template_directory_uri() . '/style.css';
}
function my_theme_styles()
{
$themeVersion = wp_get_theme()->get('Version');
// Enqueue our style.css with our own version
wp_enqueue_style('child-theme-style', get_stylesheet_directory_uri() . '/style.css',
array(), $themeVersion);
}
更新2017-01-26
当前的WP主题手册现在包含正确的修复程序::https://developer.wordpress.org/themes/advanced-topics/child-themes/#3-enqueue-stylesheet