覆盖来自子主题的父主题的包含文件

时间:2017-01-18 作者:Olivier.B

我试图从子主题重写父主题的包含文件。代码如下:



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
那么,如何防止父主题重新声明函数呢

1 个回复
SO网友:Michael2

您不能简单地覆盖该文件。

但是,您可以覆盖核心。php文件执行以下操作:

使用remove_filter / remove_action 要删除不希望运行的筛选器,请执行以下操作:

remove_action ( \'cryout_headerimage_hook\', \'fluida_header_image\' );

相关推荐