Thursday, March 27, 2014

Fwd: How to enable widget area in wordpress theme

How to enable widget area in wordpress theme

Custom widget area is enabled from function.php that is available in the themes folder.
Add the following code in function.php to enable/register widget area in the wordpress theme:
  if (function_exists('register_sidebar')) {       register_sidebar(array(        'name' => 'Sidebar Widgets',        'id'   => 'sidebar-widgets',        'description'   => 'Widget Area',        'before_widget' => '<div id="one" class="two">',        'after_widget'  => '</div>',        'before_title'  => '<h2>',        'after_title'   => '</h2>'       ));      }  

How to add widget area in wordpress theme

Once you have enabled the function in function.php you can make any area as a widget area within a wordpress theme. Add the following code to the area ( sidebar, footer, header ) where you want the widget to to make a slot and add widget to it later from widgets setting panel:

  <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar Widgets') ) : ?>        <?php endif; ?>  

NOTE: If you want more then one area to be widgetized at the same time, then you have to register sidebar in function.php more then once with different names and id's 

No comments:

Post a Comment