“remove_action(...);”从 Divi 版本 4.10.6(21 年 9 月)开始,解决方案不再有效,因为“et_divi_replace_stylesheet”操作已被删除。
我解决这个问题的方法是从 Divi/includes/builder/core.php 覆盖第 776 行(从版本 4.14.6 开始),以便函数 et_builder_should_wrap_styles() 始终返回 false:
function et_builder_should_wrap_styles() {
static $should_wrap = null;
if ( null === $should_wrap ) {
$post_id = get_the_ID();
// Warp on custom post type archives and on non-native custom post types when the builder is used.
$should_wrap = et_builder_is_custom_post_type_archive() || ( et_builder_post_is_of_custom_post_type( $post_id ) && et_pb_is_pagebuilder_used( $post_id ) );
}
// return $should_wrap; /*** ORIGINAL CODE ***/
return false; /*** NEW CODE ***/
}
然后,为了确保在 Divi 更新时不会丢失此编辑,我设置了一个操作以在每次 Divi 更新时自动重写此行:
add_action('upgrader_process_complete', 'edit_files_on_update'), 10, 2);
function edit_files_on_update($upgrader_object, $hook_extra) {
if ($hook_extra['action'] !== 'update') return false;
if ($hook_extra['type'] === 'theme' && isset($hook_extra['themes'])) {
// Divi - disable CPT CSS wrapper
if (array_search('Divi', $hook_extra['themes']) !== false) {
$file_location = get_template_directory().'/includes/builder/core.php';
$file_contents = file_get_contents($file_location);
$file_contents = str_replace('return $should_wrap;', 'return false;', $file_contents);
file_put_contents($file_location, $file_contents);
}
}
}
我知道编辑主题的原始文件在技术上是不正确的,但“正确”的替代方法是覆盖我的子主题中的整个 Divi/includes/builder/core.php 文件,该文件长 7253 行!未来的 Divi 更新很有可能会编辑该原始文件,让我没有在子主题版本中反映这些编辑。