Creating custom widget

The best option is to first create a child theme for your main theme. And than call the functions.php file in it and
First Step is to register your sidebar

register_sidebar( array(
‘name’ => __( ‘Main Sidebar’, ‘themeName’ ),
‘id’ => ‘sidebar-1’,
‘description’ => __( ‘some useful info’, ‘themeName’ ),
‘before_widget’ => ‘<aside id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</aside>’,
‘before_title’ => ‘<h3 class=”widget-title”>’,
‘after_title’ => ‘</h3>’,
) );

Than going to template where you want this widget to be displayed and adding the code

php if ( is_active_sidebar( ‘sidebar-1’ ) ) : ?>
<div id=”secondary” class=”widget-area” role=”complementary”>
php dynamic_sidebar( ‘sidebar-1’ ); ?>
</div><!– #secondary –>
endif; ?>

And that is it – you have your own custom widget ready and you can do anything with it.

%d bloggers like this: