How to create widgets and call on front end in wordpress

widgets
Widgets is common things in wordpress but it is very use full to display short content and other information on content area or sidebar on front end area. If you create custom theme then you can create widgets with some code adding on themes functions.php file and call on frontend with one line code using name of widgets:

Just add this code on your functions.php file:


if (function_exists('register_sidebar')) {
register_sidebar(array(
'name'=> 'Home introduction',
'id' => 'top_tabs',
'before_widget' => '

  • ',
    'after_widget' => '

‘,
‘before_title’ => ‘

‘,
‘after_title’ => ‘

‘,
));
register_sidebar(array(
‘name’=> ‘Top Sidebar’,
‘id’ => ‘top_sidebar’,
‘before_widget’ => ‘

  • ‘,
    ‘after_widget’ => ‘

‘,
‘before_title’ => ‘

‘,
‘after_title’ => ‘

‘,
));
register_sidebar(array(
‘name’=> ‘Left Sidebar’,
‘id’ => ‘left_sidebar’,
‘before_widget’ => ‘

  • ‘,
    ‘after_widget’ => ‘

‘,
‘before_title’ => ‘

‘,
‘after_title’ => ‘

‘,
));
register_sidebar(array(
‘name’=> ‘Right Sidebar’,
‘id’ => ‘right_sidebar’,
‘before_widget’ => ‘

  • ‘,
    ‘after_widget’ => ‘

‘,
‘before_title’ => ‘

‘,
‘after_title’ => ‘

‘,
));
}

To call on front end where you want to display widgets using this code:


if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Home introduction') ) : endif;

Download code source file click on this link

Where ‘Home introduction’ is name of widgets which is used in functions.php.

Thanks, Cheers the code