the file placed in the child theme is not included

I have modified the theme.php file located in the parent theme in the "Includes" folder, and I have placed it in the child theme also in the "Includes" folder, but my changes are not included. WordPress only reads the file placed in the parent theme folder. What is the reason for this? What should I do the modifications are included when the file is located in the child theme folder? Alternatively, how can I override a function from includes/theme.php in functions.php? I can’t override the function because there’s a redeclaration error.

Edit 7.05.2020

@JacobPeattie - Thanks a lot. I read it. I don't know if I understand it all right. My English isn't very good yet. I wrote so in functions.php:

if ( ! function_exists( 'bimber_capture_entry_featured_media' ) ) :
function bimber_capture_entry_featured_media_my_modifications( $args ) {

//function code with my modifications

}
endif;

It was successful added, but doesn’t work.

Maybe it’s usefull information:

  1. File theme.php is added in functions.php file in parentTheme/includes folder in this way: require_once BIMBER_INCLUDES_DIR . 'theme.php';

  2. Function is called by ‘echo’ in another function.

Here are php files:

Topic child-theme pluggable Wordpress

Category Web


You want to replace bimber_capture_entry_featured_media in your child theme. In the theme.php file you've given us you can see that this is only called in one place, from bimber_render_entry_featured_media, and the call is wrapped in a filter:

if ( apply_filters( 'bimber_render_entry_featured_media', true, $args ) ) {
    echo bimber_capture_entry_featured_media( $args );
}

where returning false from the filter will cancel the call to the default code. Assuming that's true, that nothing else calls this function without the filter guard, what you can do then instead is

  1. implement the bimber_render_entry_featured_media filter; choose a low priority if there's anything else that implements this, but I don't see anything in these files
  2. in the filter call your replacement bimber_capture_entry_featured_media_my_modifications and echo the result
  3. return false from the filter to cancel the call to the original unmodified code.

e.g. (untested)

function bimber_render_entry_featured_media_filter_my_modifications( $flag, $args ) {
    if ($flag) {
        echo bimber_capture_entry_featured_media_my_modifications( $args );
    }
    return false;
}
add_filter( 'bimber_render_entry_featured_media',
            'bimber_render_entry_featured_media_filter_my_modifications', 10, 2 );

However there are plenty of hooks in the original method too, so depending on what you're trying to do you might be able to use those to change the behaviour rather than completely overriding the method.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.