To register a widget area for you theme you should use the register_sidebar function in your theme’s function.php.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php /** * Register a sidebars and widget area. * */ function your_new_widget_area() { register_sidebar( array( ‘name’ => __(‘Name of the Widget Area’,‘text-domain’), ‘id’ => ‘id_name’, ‘description’ => ‘Some description’, ‘class’ => ‘the-class’, ‘before_widget’ => ‘<div>’, ‘after_widget’ => ‘</div>’, ‘before_title’ => ‘<h2 class=”widget-title”>’, ‘after_title’ => ‘</h2>’, ) ); } add_action( ‘widgets_init’, ‘your_new_widget_area’ ); ?> |
This function will register the widget’s area through the ‘widgets_init’ hook.
For more specification on register_sidebar please see here.
Next step is to set the place where we want to see the widgets to be displayed. Put the following code in your html code where you want to have to widget’s block to appear.
1 |
<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘id_name’) ) : endif;?> |
Now you can go to your admin panel Appearance – >Widgets and navigate through your new widget area.