$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Can't override footer.php in child theme|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Can't override footer.php in child theme

matteradmin7PV0评论

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.

And this is what i added in the child theme:

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="" 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="/" 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(); ?>

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.

And this is what i added in the child theme:

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" 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/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(); ?>
Share Improve this question edited Feb 7, 2017 at 13:55 treisto asked Feb 7, 2017 at 9:35 treistotreisto 211 silver badge3 bronze badges 4
  • Did you activate the child theme? – Max Yudin Commented Feb 7, 2017 at 11:48
  • Yep, the child 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 reads the functions.php fom the child theme – treisto Commented Feb 7, 2017 at 12:20
  • I doubt your theme fully supports child themes. There was not mentioned otherwise on their site. – Max Yudin Commented Feb 7, 2017 at 13:16
  • If it should have been built to support child themes, then yes, it is indeed a very high chance it doesn't support child themes. Should I just declare this case closed in this case?, there is usually more pain than gain if one tries to customize a theme which was not built on purpose with a child theme in mind? – treisto Commented Feb 7, 2017 at 13:42
Add a comment  | 

4 Answers 4

Reset to default 1

My friend, just take a look at their codex here https://codex.wordpress/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

Quickly looking over this as work...

But add:

<?php get_footer(); ?>

into your template files (This should be there... you may have to call the footer-set.php and footer-tag.php files too)

you shouldn't need:

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

In your Functions.php too

If this is incorrect ill help more when I'm home

First of all you don't need to call footer files inside functions.php file. So remove these lines first.

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

As you said your child theme is working fine so let's debug why your footer.php file is not working. I don't know where you are calling footer-set.php and footer-tag.php I am assuming you need them inside footer.php file. For debugging remove old files for now and create new file with the name of footer.php and leave it empty only closing body and html tags will be there. Then your footer should be empty on front-end try try these steps and then let me know what happens.

It seems like the theme do not use the wordpress "theme agnostic" template loading APIs, in this case get_footer, or any other flexible way, which means that the footer just can not be changed by a child theme.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far