Are you a person interested in adding a new widget area to your WordPress site? Many templates have widgets in the sidebars, or footer, but, perhaps you need another widget area, for example, in the header. The following explains how to create a new widget area.
Adding a new widget area requires two fairly simple steps:
- Add content to the functions.php file
- Add a line of code where you want the new widget area
Step 1 – add a widget area definition to functions.php
Add the following code to the end of your functions.php file. (You may create a custom functions.php file in your theme directory)
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Header Area',
'id' => 'header-area',
'description' => 'This is the header area.',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
}
The preceding code would define a widget area that will have the label “Header Area” in the administration area. This widget would have an “h4” header for the title, and bracket the widget with “div.” You can change the widget wrapper and header type to meet your needs.
Add some code where you want the widget to display
Decide where you want the widget displayed. If this were to be added to the header area, modify file header.php, including the following code where you want the widget inserted.
<div id="header-area">
<?php if (function_exists('dynamic_sidebar') &&
dynamic_sidebar('header-area')) endif; ?>
</div>