我试图从子主题重写父主题的包含文件。代码如下:
parentTheme/functions.php
<?php
define ( "_CRYOUT_THEME_NAME", "fluida" );
define ( "_CRYOUT_THEME_VERSION", "1.2.6" );
require_once( get_template_directory() . "/admin/main.php" );
require_once( get_template_directory() . "/includes/setup.php" );
require_once( get_template_directory() . "/includes/styles.php" );
require_once( get_template_directory() . "/includes/loop.php" );
require_once( get_template_directory() . "/includes/comments.php" );
require_once( get_template_directory() . "/includes/core.php" );
require_once( get_template_directory() . "/includes/hooks.php" );
require_once( get_template_directory() . "/includes/meta.php" );
require_once( get_template_directory() . "/includes/landing-page.php" );
childTheme/functions.php
<?php
add_action( \'wp_enqueue_scripts\', \'my_theme_enqueue_styles\' );
function my_theme_enqueue_styles() {
wp_enqueue_style( \'parent-style\', get_template_directory_uri() . \'/style.css\' );
}
?>
我想覆盖
/includes/core.php 文件我有一个
childTheme/includes/core.php 文件
但当我更改它时,我的网站上没有任何更改
我已尝试将此代码添加到
childTheme/functions.php :
require_once( get_stylesheet_directory() . "/includes/core.php");
但它会在我的网站上呈现一个空白页面。
编辑:
我尝试过:
<?php
/**
* Enqueues child theme stylesheet, loading first the parent theme stylesheet.
*/
require_once( get_stylesheet_directory() . "/includes/core.php" ); // Core functions
function themify_custom_enqueue_child_theme_styles() {
wp_enqueue_style( \'parent-theme-css\', get_template_directory_uri() . \'/style.css\' );
}
add_action( \'wp_enqueue_scripts\', \'themify_custom_enqueue_child_theme_styles\', 11 );
但我有一个错误:
Cannot redeclare xxx_function_name
(previously declared in /var/www/html/mywebsite/wp-content/themes/***childTheme***/includes/core.php:340)
in /var/www/html/tpevegetarisme/wp-content/themes/***parentTheme***/includes/core.php on line 340
那么,如何防止父主题重新声明函数呢