更新到 Wordpress 子主题 function.php 导致网站中断

Update to Wordpress child theme function.php breaks site

我的 wordpress 网站上有一个子主题,修改后的function.php如下

<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:

if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
 function chld_thm_cfg_locale_css( $uri ){
 if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )
 $uri = get_template_directory_uri() . '/rtl.css';
 return $uri;
 }
endif;
add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );

if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
 function chld_thm_cfg_parent_css() {
 wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( 'fil-theme-flaticon','fil-theme-font-awesome','fil-theme-icomoon','fil-theme-pe-icon-7-stroke','fil-theme-simple','fil-theme-stroke','woocommerce-general' ) );
 }
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 );

?>

// END ENQUEUE PARENT ACTION

但是,如果我将其更改为以下内容,添加一些我最初添加到主题中的代码 function.php 我在转到结帐页面时遇到严重错误,大概是因为它是尝试调用其中一个函数。

<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:

if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
 function chld_thm_cfg_locale_css( $uri ){
 if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )
 $uri = get_template_directory_uri() . '/rtl.css';
 return $uri;
 }
endif;
add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );

if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
 function chld_thm_cfg_parent_css() {
 wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( 'fil-theme-flaticon','fil-theme-font-awesome','fil-theme-icomoon','fil-theme-pe-icon-7-stroke','fil-theme-simple','fil-theme-stroke','woocommerce-general' ) );
 }
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 );

add_filter( 'wc_session_use_secure_cookie', '__return_true' );


add_action('woocommerce_before_cart_contents', 'checkout_message');

function checkout_message() {
echo '<div class="checkout_message"><h4 style="font-size: 20px;color: #ff0000;">
<p>Please be aware due to Covid-19 shipping times can be impacted.</p>
</h4>
</div>'; }

wp_deregister_script('jquery');
wp_register_script('jquery', '//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js';, false, null);
wp_enqueue_script('jquery');


?>

// END ENQUEUE PARENT ACTION

我认为子主题会覆盖主主题中的 function.php 文件。这似乎不是这种情况,因为我试图添加到子主题 function.php 的消息仍然显示。仅在子主题 function.php 中的其他代码似乎也能正常工作。

知道如何将要添加的自定义代码从主主题 function.php 移动到子主题吗?如果主题更新,我想避免丢失这些。

您需要将其从父主题中删除或将其包装在

if(!function_exists('')) {
}