How to make a custom widget area in wordpress?

First of all place this code in function.php file to register a widget. Make sure that this widget name is unique and different for each.
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Extra Widgets',
'id' => 'extra-widgets',
'description' => 'The extra widgets for your website.',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>'
));
}

after this, You can place this below code where you want to show the widget content:
<?php 
if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Extra Widgets')) :
endif; ?>

1 comment: