How to remove and add WordPress widgets to child theme

Removing the widgets from the wordrpress child theme, by default twentyten has some sidebar widgets we can make use of them in child theme or we can remove these widgets and create set of new widgets for this child theme.

For removing the widgets we have to add this code to the functions.php with in the child theme.

function remove_some_widgets(){

        // Unregsiter some of the TwentyTen sidebars
        unregister_sidebar( 'primary-widget-area' );
        unregister_sidebar( 'secondary-widget-area' );
        unregister_sidebar( 'first-footer-widget-area' );
        unregister_sidebar( 'second-footer-widget-area' );
        unregister_sidebar( 'third-footer-widget-area' );
        unregister_sidebar( 'fourth-footer-widget-area' );
}
add_action( 'widgets_init', 'remove_some_widgets', 11 );

After that we can create some new widgets by using the below code. Here we are creating a function with name of “theme widgets”, in this we are using wordpress function register_sidebar, in this function we are passing an array of arguments.

function theme_widgets(){
        register_sidebar( array(
                'name' => __( 'Header Widget Area', 'twentyten' ),
                'id' => 'header-widget-area',
                'description' => __( 'The Header widget area', 'twentyten' ),
                'before_title' => '<h3 class="widget-title">',
                'after_title' => '</h3>',
        ) );
}

add_action( 'widgets_init', 'theme_widgets' );

after adding the above we can see the widget in the wordpress admin widgets page, after that we have to call the widget in the theme, we can call the widget in theme using the below code.

<?php if ( !function_exists('dynamic_sidebar') ||
!dynamic_sidebar('Header Widget Area') ) : ?>
<?php endif; ?>

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe