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:
File theme.php is added in functions.php file in parentTheme/includes folder in this way:
require_once BIMBER_INCLUDES_DIR . 'theme.php';
Function is called by ‘echo’ in another function.
Here are php files:
- .php.txt
- .php.txt
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:
File theme.php is added in functions.php file in parentTheme/includes folder in this way:
require_once BIMBER_INCLUDES_DIR . 'theme.php';
Function is called by ‘echo’ in another function.
Here are php files:
- http://srv19859.microhost.pl/phpfiles/functions.php.txt
- http://srv19859.microhost.pl/phpfiles/theme.php.txt
1 Answer
Reset to default 2You 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
- 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
- in the filter call your replacement
bimber_capture_entry_featured_media_my_modifications
and echo the result - 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.
bimber_capture_entry_featured_media_my_modifications
- you'd have to give it exactly the same function name. But unless the function is also pluggable in the parent theme this won't do any good. (I'd have expected the parent theme would be loaded first but I think I'm wrong and the child is loaded first.) – Rup Commented May 7, 2020 at 11:38