Multiple Dynamic Sidebars

Edit Functions.php for Multiple Dynamic Sidebars

modify the default function.php from:

1
2
3
4
<?php
if ( function_exists('register_sidebar') )
register_sidebar();
?>

to the new code below (with h4 subtitles and non-default unordered lists examples):

1
2
3
4
5
6
7
8
9
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
?>

To support multiple sidebars, specify that multiple sidebars be used and use a unique name. (Sidebar1, Sidebar2 etc and as many as you like) The code now looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'sidebar1',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
register_sidebar(array('name'=>'sidebar2',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>',
));
?>

Add Dynamic Sidebars to Wordpress Template

Now you need to place the code in the wordpress theme template where you want the relevant wordpress widgets to work. Instead of the previous code, you can place the different dynamic sidebars in different areas of the template.
Sidebar1 code goes like this:

1
2
3
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar1') ) : ?>
<?php endif; ?>

Sidebar2 code goes like this:

1
2
3
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('sidebar2') ) : ?>
<?php endif; ?>

From: Multiple Dynamic Sidebars


Leave a Comment