Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I add some extra sidebar locations for widgets in a child theme. The difficulty I'm having is because the parent theme uses some pretty gnarly setup to define the current sidebars.

I would like to add a sidebar area to my site's header and another sidebar area to the home template.

The parent theme's functions.php file starts off with:


add_action( 'after_setup_theme', 'et_setup_theme' );
if ( ! function_exists( 'et_setup_theme' ) ){
    function et_setup_theme(){
        global $themename, $shortname;
        $themename = "Chameleon";
        $shortname = "chameleon";

        require_once(TEMPLATEPATH . '/epanel/custom_functions.php'); 

        require_once(TEMPLATEPATH . '/includes/functions/comments.php'); 

        require_once(TEMPLATEPATH . '/includes/functions/sidebars.php'); 


        require_once(TEMPLATEPATH . '/epanel/options_chameleon.php');

        require_once(TEMPLATEPATH . '/epanel/core_functions.php'); 

        require_once(TEMPLATEPATH . '/epanel/post_thumbnails_chameleon.php');

        include(TEMPLATEPATH . '/includes/widgets.php');

        add_action( 'wp_enqueue_scripts', 'et_add_responsive_shortcodes_css', 11 );

        add_action( 'pre_get_posts', 'et_home_posts_query' );

        add_action( 'et_epanel_changing_options', 'et_delete_featured_ids_cache' );
        add_action( 'delete_post', 'et_delete_featured_ids_cache' );    
        add_action( 'save_post', 'et_delete_featured_ids_cache' );

Where "require_once(TEMPLATEPATH . '/includes/functions/sidebars.php');" is the only reference to sidebars in this file.

So the sidebars.php file in the includes directory contains the following:

if ( function_exists('register_sidebar') ) {
        'name' => 'Sidebar',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div> <!-- end .widget -->',
        'before_title' => '<h3 class="title">',
        'after_title' => '</h3>',

        'name' => 'Footer',
        'before_widget' => '<div id="%1$s" class="footer-widget %2$s">',
        'after_widget' => '</div> <!-- end .footer-widget -->',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>',

        'name' => 'Homepage',
        'before_widget' => '<div id="%1$s" class="main-widget %2$s">',
        'after_widget' => '</div> <!-- end .main-widget -->',
        'before_title' => '<h3 class="title">',
        'after_title' => '</h3>',

There is a sidebar.php file in the theme's root directory that contains the following:

<div id="sidebar">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?> 
    <?php endif; ?>
</div> <!-- end #sidebar -->

So, let's (for now) work with adding a new sidebar area to the home template... The home.php template (which I have a modified copy of in my child theme folder) contains the following references to sidebars:

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Homepage') ) : ?> 
            <?php endif; ?>

and just before the end of the code for this template...

<?php get_sidebar(); ?>

My themes folder directory structure appears as so:

mywebsiteroot > wp-content > themes > Chameleon > includes | home.php
mywebsiteroot > wp-content > themes > Chameleon > includes | functions.php
mywebsiteroot > wp-content > themes > Chameleon > includes | sidebar.php
mywebsiteroot > wp-content > themes > Chameleon > includes | style.css
mywebsiteroot > wp-content > themes > Chameleon > includes > functions > sidebar.php
mywebsiteroot > wp-content > themes > Chameleon > includes > css > other stylesheets...

mywebsiteroot > wp-content > themes > lppscustom | home.php
mywebsiteroot > wp-content > themes > lppscustom | header.php
mywebsiteroot > wp-content > themes > lppscustom | footer.php
mywebsiteroot > wp-content > themes > lppscustom | style.css

And... this is where I'm stuck. I know you can have your own custom functions.php and sidebar.php files in the child theme folder, but how do I structure them? Do I have to include all code from the parent theme's files? If so, how do I modify the code so any reference to sub-directories are relative? If not, how do I make it load the parent theme's function file and sidebar file as well as my custom ones?

Any help would be greatly appreciated.

share|improve this question

1 Answer 1

Functions.php is shared for parent/child themes unlike other files which will be overridden. What that means is that WordPress will load both the parent and the child functions.php.

In your case it sounds like you would simply create a child functions.php and then a create new register_sidebar .

Then use dynamic_sidebar whenever you want in your theme template to call your new sidebar.

In my opinion the best method for child themes is to try to avoid duplicate files as much as possible, keep the parent loaded as is, and create your own custom child files. Of course you will have to override some files, but try to keep it modular.

If your theme uses any hard-coded path values and improper function calls for file inclusion then overriding it via the child theme will break stuff, unless you duplicate the structure (except for functions.php).

For reference:

For example:
get_stylesheet_directory_uri will use the child
get template directory uri will not

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.