Create a dynamic sidebar using Widget in WordPress


1. Open functions.php file and add the code below:


add_action('widgets_init', 'sidebar_action_name');
  

2. Then Write the following function at functions.php


function sidebar_action_name() {
	if (function_exists('register_sidebar')) {
		register_sidebar(array(
			'name' => 'Name-To-Display',
			'before_widget' => '<div class="widget_top">',
			'after_widget' => '</div><div class="widget_foot"></div>',
			'before_title' => '<div class="widget_title">',
			'after_title' => '</div>',
		));
	}
}
  

3. Now this is the time to show dynamic sidebar data on UI. Just copy & paste the following code


<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar("Name-To-Display")) : ?>

<?php endif; ?>	
    
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s