How do I override a sidebar that is registered in a parent theme when using a child theme?

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

Read More

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>',
    )); 
}

Related posts

2 comments

  1. 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-#”…

  2. 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... 
         *  (look for a string data-widget-area-id="footer-4") 
         *  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>',
        )); 
    }
    

Comments are closed.