• Hi,

    Modifications in the theme.php file, which is located in the […]myTheme/includes/ folder are only included if the file is located 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’s theme folder?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter reti

    (@reti)

    Alternatively, how can I override a function from includes/theme.php in functions.php?

    • This reply was modified 4 years, 10 months ago by reti.

    To overwrite functions of the parent theme, copy the functions.php to child theme.

    Once copied, you can make changes to this new child functions.php file by adding snippets of code. Ensure that the child theme is active.

    Thread Starter reti

    (@reti)

    My functions.php is already in child theme folder and child theme is active.

    Thread Starter reti

    (@reti)

    I can’t override the function because there’s a redeclaration error.

    Hi,

    From stackoverflow

    Redeclaring a function in a child theme only works when the parent themes’ function is wrapped in a

    if( !function_exists( ‘function_name’ )):

    condition. Then you can simply just copy the complete function to the child theme and do whatever modifications you need to do.

    If the parent themes’ functions aren’t wrapped in that if conditional statement, and if no filters or hooks are supplied in the function, it will be best to copy the function to your child theme, rename that function, do your modifications and then update your template files accordingly to reflect the new function.

    You can try to first remove the function with

    
    remove_filter( 'hook', 'function_name' );

    and then add the function again with the new name and same hook.

    For Example

    
        function remove_content_filter() {
    
           remove_filter( 'the_content', 'function_name' );
    
        }
    
        add_action( 'after_setup_theme', 'remove_content_filter' );
    
        function new_function_name( $output ) {
            //some code here
            return $output;
        }
    
        add_filter( 'the_content', 'new_function_name' );
    
    Thread Starter reti

    (@reti)

    Thank you very much for your answer. I called that function:

    
    <?php
    function checkFunction(){
    	if( !function_exists( ‘bimber_render_entry_featured_media’ )) {
    	?> <script>alert("Hello!")</script> <?php
    	}
    }
    add_action('wp_footer', 'checkFunction');
    ?>
    

    The ‘Hello!’ alert appears, so the ‘bimber_render_entry_featured_media’ function should be overwritten in child theme functions.php, right? This is not so. A message about the redeclaration will appear.

    • This reply was modified 4 years, 10 months ago by reti.
    Thread Starter reti

    (@reti)

    I wrote so:

    
    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:
    https://srv19859.microhost.com.pl/phpfiles/functions.php.txt
    https://srv19859.microhost.com.pl/phpfiles/theme.php.txt

    I would suggest you to get in touch with the theme author himself and get best solution.

    Thread Starter reti

    (@reti)

    They don’t care about it. All I hear all the time is that it’s not a theme-related question. I asked the same question on StackExchange. It’s solved. You’ve helped a lot too. Thanks!

    • This reply was modified 4 years, 10 months ago by reti.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘modifications aren’t included in a child theme’ is closed to new replies.