1

I am trying to override a parent theme's include file from a child theme. Here is the code:



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' );
}

?>

And I want to override the /includes/core.php file
I have a childTheme/includes/core.php file
But when I change it, there are no changes on my site.
I have tried to add this code on my childTheme/functions.php :

require_once( get_stylesheet_directory() . "/includes/core.php");

But it renders a blank page on my site.

EDIT :

I have tryed this :

<?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 );

But I got this error :

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

So how can I do to prevent parent theme to redeclare a function

  • Templates and template parts from a parent theme can be overridden by copying the files to the same location in the child theme, but this does not apply to various PHP includes. Also, turn on error reporting so you can figure out what error is causing the white screen. – Dave Romsey Jan 18 '17 at 22:24
  • Thanks, I figured you'd be getting an error related to re-declaring a function. You can try posting the contents of the core.php file to try and get additional help. Overriding may or may not be possible depending on how the parent theme is built. – Dave Romsey Jan 18 '17 at 22:51
3

You cannot simply override that file.

You can however override what the core.php file does:

Use remove_filter / remove_action to remove filters you do not want to be run:

remove_action ( 'cryout_headerimage_hook', 'fluida_header_image' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.