Adding Widget Area to Child Theme

Last Updated: October 6, 2013 | Reading Time: < 1 minute

If you work on Child Theme, to add widget must follow the parent’s theme rule. Or if you makes a parent theme, make sure it’s follow-able by child theme to modify it.
[php]
function new_childtheme_sidebars() {
register_sidebar(array(
‘name’ => ‘Sidebar Sidebar’,
‘before_widget’ => ‘<div class="item">’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h3 class="sub">’,
‘after_title’ => ‘</h3>’,
));
register_sidebar(array(
‘name’ => ‘Footer Widget’,
‘before_widget’ => ‘<div class="item">’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h3 class="sub">’,
‘after_title’ => ‘</h3>’,
));
}
add_action( ‘widgets_init’, ‘new_childtheme_sidebars’, 11 );
[/php]
Parent theme, if not defined, take hook priority at 10. Child theme, must take the lower priority to be executed after parent theme, we use 11 on the code above.

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Any idea? Fill the comment below

    This site uses Akismet to reduce spam. Learn how your comment data is processed.