Register Sidebar Widget Area

Use this code to add a new widget area / sidebar.

1
2
3
4
5
6
7
8
9
10
11
12
13
//Register Sidebars
if (function_exists('register_sidebar')) {
	register_sidebar(array(	
		'name'=> 'Sidebar 1',
		'id' => 'sidebar 1',
		'description' => 'This is a sidebar / widget area',
		'before_widget' => '<div class="widget %1$s">', // '%1$s' adds a unique class for each widget area added
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>'
	)
	);		
}

Use this code to add multiple new widget areas / sidebars.
I prefer to use this in its own sidebar.php or widgets.php file, and then include that file in my main functions.php file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
//Register the sidebar
if ( function_exists ('register_sidebar')) {
	register_sidebar(array(
		'name' => 'Main Sidebar',
		'id' => 'sidebar1',
		'description' => 'This is the main sidebar',
		'before_widget' => '<div class="widget %1$s">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>'
		)
	);
}
if ( function_exists ('register_sidebar')) {
	register_sidebar(array(
		'name' => 'Footer 1',
		'id' => 'footer1',
		'description' => 'This is the left footer widget',
		'before_widget' => '<div class="widget %1$s">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>'
		)
	);
}
if ( function_exists ('register_sidebar')) {
	register_sidebar(array(
		'name' => 'Footer 2',
		'id' => 'footer2',
		'description' => 'This is the middle footer widget',
		'before_widget' => '<div class="widget %1$s">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>'
		)
	);
}
if ( function_exists ('register_sidebar')) {
	register_sidebar(array(
		'name' => 'Footer 3',
		'id' => 'footer3',
		'description' => 'This is the right footer widget',
		'before_widget' => '<div class="widget %1$s">',
		'after_widget' => '</div>',
		'before_title' => '<h4>',
		'after_title' => '</h4>'
		)
	);
}

To Place These Sidebars into Your Theme, you need to put this code inside your theme file. In this example, we are inserting widget areas into the footer.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<div id="footer">
		<div class="row split">
			<div class="third">
				<?php if ( ! dynamic_sidebar('footer1')) : ?>
				<h2>This is Footer 1</h2>
				<?php endif; ?>
			</div>
			<div class="third">
				<?php if ( ! dynamic_sidebar('footer2')) : ?>
				<h2>This is Footer 2</h2>
				<?php endif; ?>
			</div>
			<div class="third">
				<?php if ( ! dynamic_sidebar('footer3')) : ?>
				<h2>This is Footer 3</h2>
				<?php endif; ?>
			</div>
		</div>
	</div>
 
	</div>
<?php wp_footer(); ?>
</body>
</html>