Add custom wordpress widget

Hi,

To add a new custom widget in WordPress you can do following things:

Add the below code in WordPress theme functions.php .

if (function_exists(‘register_sidebar’)) {
register_sidebar(array(
‘name’ => ‘AdditionalWidgets’,
‘id’ => ‘additional-widgets’,
‘description’ => ‘The Middle widgets for placing the content in middle.’,
‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,
‘after_widget’ => ‘</div>’,
‘before_title’ => ‘<h2>’,
‘after_title’ => ‘</h2>’
));
}

The name and id should be unique.

To display this theme try the below code:

<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘AdditioanlWidgets’) ) :  dynamic_sidebar(‘AdditionalWidgets’) ;  endif; ?>

Leave a Reply

Your email address will not be published. Required fields are marked *