1

I currently am using a child theme, and its parent theme has registered sidebars already..

My. problem is that i want to change the parent theme's dynamic sidebar

From:

register_sidebar(array(
    'name' => 'Footer',
    'before_widget' => '<div class="span3">',
    'after_widget' => '</div>',
    'before_title' => '<h6 style="text-transform: uppercase !important; font-weight:600; !important">',
    'after_title' => '</h6><hr>',
));

To:

register_sidebar(array(
    'name' => 'Footer',
    'before_widget' => '<div class="span3">',
    'after_widget' => '</div>',
    'before_title' => '<h6 class="footer-widget-item">',
    'after_title' => '</h6><hr>',
));

Now, how am I supposed to do that? I have found this hook called after_setup_theme from here but I'm a bit confused on how to do it. Should I deregister the sidebar then register it again?


UPDATE:

Here is my attempt but it didn't work:

add_action( 'after_setup_theme', 'parent_override' );
function parent_override() {
    unregister_sidebar('Footer');   
    register_sidebar(array(
        'name' => 'Footer',
        'before_widget' => '<div class="span3">',
        'after_widget' => '</div>',
        'before_title' => '<h6 class="footer-widgets-item">',
        'after_title' => '</h6><hr>',
    )); 
}
  • Where is the register_sidebar() call in the parent Theme? Is is directly in functions.php, or is it inside a callback, hooked into an action with add_action()? – Chip Bennett Nov 7 '13 at 20:09
  • it's called directly in functions.php.. just wrapped inside an if(function_exists('register_sidebar')){ } clause – reikyoushin Nov 7 '13 at 20:13
  • @ChipBennett If it is not hooked into an action then it is impossible? – reikyoushin Nov 7 '13 at 20:23
2

Here is what worked:

add_action( 'after_setup_theme', 'parent_override' );
function parent_override() {

    unregister_sidebar('sidebar-4'); 
    /** I have looked for the ID of the sidebar by looking at        
     *  the source code in the admin.. and saw the widget's id="sidebar-4"
     */ 

    register_sidebar(array(
        'name' => 'Footer',
        'before_widget' => '<div class="span3">',
        'after_widget' => '</div>',
        'before_title' => '<h6 class="footer-widgets-item">',
        'after_title' => '</h6><hr>',
    )); 
}

It seems that the id is not a slug of the name, and if you did not specify an id upon registering the sidebar, it will have an id of "sidebar-#"...

| improve this answer | |
  • Yep, the Parent Theme is _doing_it_wrong() by 1) not putting the register_sidebar() call inside a callback hooked into widgets_init, and 2) not providing an ID for each registered sidebar. – Chip Bennett Nov 7 '13 at 21:05
  • we bought this theme so, we couldn't change it aotm.. i guess i'll just have to do it this way then.. – reikyoushin Nov 7 '13 at 21:06
0
add_action( 'widgets_init', 'parent_override',11 );
function parent_override() {

    unregister_sidebar('sidebar-4'); 
    /** I have looked for the ID of the sidebar by looking at        
     *  the source code in the admin.. and saw the widget's id="sidebar-4"
     */ 

    register_sidebar(array(
        'name' => 'Footer',
        'before_widget' => '<div class="span3">',
        'after_widget' => '</div>',
        'before_title' => '<h6 class="footer-widgets-item">',
        'after_title' => '</h6><hr>',
    )); 
}
| improve this answer | |
  • Just change add action and By lowering the priority of our action, we ensure that it is called after the parent theme’s functions.php file is loaded. – Rushang Shah Nov 13 '19 at 14:39
  • Instead of posting the explanation as a comment, just edit to include the explanation in your answer. – butlerblog Nov 13 '19 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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