Monday, 19 October 2015

How to add custom widget?

Add the below code in your  functions.php


function mycustom_widgets_init() {
    register_sidebar( array(
        'name'          => 'Right sidebar1',
        'id'            => 'r    ight_1',
        'before_widget' => '<div>',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="rounded">',
        'after_title'   => '</h2>')
     );
}
add_action( 'widgets_init', 'mycustom_widgets_init' );

Add the below code in your sidebar file.


<?php if ( is_active_sidebar( 'right_1' ) ) : ?>
    <div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
        <?php dynamic_sidebar( 'right_1' ); ?>
    </div><!-- #primary-sidebar -->
    <?php endif; ?>

No comments:

Post a Comment