In blog

Widgets can be extremely useful and handy. Some theme allows you to create widget. But how do you place them in your theme? In this article we will provide you wordpress snippets on

  1. Registering or creating wordpress widget
  2. Integrating the widget in your theme

1. Register wordpress widget

 * Register Widget Area.
function wpgyan_widgets_init() {
register_sidebar( array(
'name' => 'Header Sidebar',
'id' => 'header_sidebar',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
add_action( 'widgets_init', 'wpscube_widgets_init' );
Note: I have added prefix wpscube_ to function name at two places at top and at bottom.You can change to a prefix of your choice.
Please read wordpress codex on other customization you could do

2. Integrate widget in your theme

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('header_sidebar') ) :
endif; ?>
header_sidebar = widget name defined in step 1 No go to Appearance > Widgets you will see Header Sidebar on the right hand side. You can add any kind of widget to it If you want to register multiple widget. Use the above code but keep the widget name unique  
Recent Posts