I’m having a hard time trying to override my parent theme’s footer.php, footer-set.php and footer-tag.php from my child theme.

I have just tried to copy-paste and modify them. No success. Maybe they are being read but probably later on, the ones from the parent prevail.

I have also tried to request them from the functions.php in the child theme with no luck:

<?php
function my_theme_enqueue_styles() {

    $parent_style="parent-style"; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
    require_once get_stylesheet_directory() . '/footer.php';
    require_once get_stylesheet_directory() . '/footer-set.php';
    require_once get_stylesheet_directory() . '/footer-tag.php';

    /*include( get_stylesheet_directory() . '../footer.php' ); 
    include( get_stylesheet_directory() . '../footer-set.php' ); 
    include( get_stylesheet_directory() . '../footer-tag.php' ); */
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>

The child theme is active and it works. I know this because the style.css works – it has effect. Also if i write something wrong in the functions.php in the child folder, it would throw an error. So it parses the functions.php fom the child theme.

I presume I have to de-register the footer.php somewhere/somehow, but I have no idea where and how to.

This is my parent’s theme structure, and these 3 are the files I am trying to override.

enter image description here

And this is what i added in the child theme:

enter image description here

As more info in case it would be useful, this is how the footer.php looks like:

<?php if ( tt_is_sidebar_active('footer_widget_area') ) { ?>
<section id="footer-widgets" class="clear">     
    <ul class="content-block xoxo">

        <?php dynamic_sidebar('footer_widget_area'); ?>

    </ul>
</section>
<?php } ?>
</section>
<?php global $template_url;?>
    <footer id="footer">
        <section class="content-block" style="margin-bottom:0;">
            <p class="copyright left">&copy; <?php echo date('Y');?> Queen Latifah Weight Loss</a>
             | Theme By <a href="http://allinonetheme.com" title="All In One Theme" rel="nofollow">All In One Theme</a></p>
            <ul id="footer-nav" class="right">
                <li><a href="<?php bloginfo('url');?>" title="Visit HomePage">Home</a></li>
                    <?php //About Us Page
                    $footer_item = get_option('tt_footer_about');
                    if($footer_item && $footer_item != '' && is_numeric($footer_item)) { 
                    $page = get_page($footer_item);
                    ?>
                    <li><a href="<?php echo get_permalink($footer_item);?>" title="<?php echo $page->post_title; ?>">About</a></li>
                    <?php
                    }
                    unset($footer_item); unset($page);
                    ?>
                    <?php //Terms Of Service Page
                    $footer_item = get_option('tt_footer_tos');
                    if($footer_item && $footer_item != '' && is_numeric($footer_item)) { 
                    $page = get_page($footer_item);
                    ?>
                    <li><a href="<?php echo get_permalink($footer_item);?>" title="<?php echo $page->post_title; ?>" rel="nofollow">Terms Of Service</a></li>
                    <?php
                    }
                    unset($footer_item); unset($page);
                    ?>
                    <?php //Privacy Policy Page
                    $footer_item = get_option('tt_footer_privacy');
                    if($footer_item && $footer_item != '' && is_numeric($footer_item)) { 
                    $page = get_page($footer_item);
                    ?>
                    <li><a href="<?php echo get_permalink($footer_item);?>" title="<?php echo $page->post_title; ?>" rel="nofollow">Privacy Policy</a></li>
                    <?php
                    }
                    unset($footer_item); unset($page);
                    ?>
                    <?php //Contact Us Page
                    $footer_item = get_option('tt_footer_contact');
                    if($footer_item && $footer_item != '' && is_numeric($footer_item)) { 
                    $page = get_page($footer_item);
                    ?>
                    <li><a href="<?php echo get_permalink($footer_item);?>" title="<?php echo $page->post_title; ?>" rel="nofollow">Contact</a></li>
                    <?php
                    }
                    unset($footer_item); unset($page);
                    ?>              <li><a href="http://www.queenlatifahweightloss.com/resources/" title="Resources" rel="nofollow">Resources</a></li>
            </ul>

        </section>
    </footer>
    <?php wp_footer();?>
</body>
</html>

I also have this in functions.php:

//Get Theme Specific Footer
function tt_get_footer() {

    $footer = get_option('tt_footer_layout');

    if($footer == 'tag') {

        include('footer-tag.php');

    } else if ($footer == 'set') {

        include('footer-set.php');

    } else if ($footer == 'custom' || $footer == 'no') {

        include('footer.php');
    } 
}

At the end of index.php I have:

<?php tt_get_footer(); ?>

4 Answers
4

My friend, just take a look at their codex here https://codex.wordpress.org/Function_Reference/get_footer and you will know how. In your case, no need to add these

require_once get_stylesheet_directory() . '/footer.php';
require_once get_stylesheet_directory() . '/footer-set.php';
require_once get_stylesheet_directory() . '/footer-tag.php';

You only need to repair your tt_get_footer like this

//Get Theme Specific Footer
function tt_get_footer() {

    $footer = get_option('tt_footer_layout');

    if($footer == 'tag') {

        get_footer('tag');

    } else if ($footer == 'set') {

        get_footer('set');

    } else {

        get_footer(); // This one will use footer.php
    } 
}

Then you will get your child theme footer overriding

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *