February 5

Define Multiple Sidebars By Name

In functions.php file of the active theme, copy and paste Example Code 1. This example creates 4 widget blocks with the names Sidebar1, 2, 3 and 4. Modify the name to suit. You can also delete the before_widget, after_widget, before_title, after_title lines if you do not need them. Add more as needed or delete the sidebar ‘sets’ if you do not need as many.

Step 1

Example Code 1
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'sidebar1',
'before_widget' => '<div id="%1$s">', // Removes <li>
'after_widget' => '</div>', // Removes </li>
'before_title' => '<h3>', // Replaces <h2>
'after_title' => '</h3>', // Replaces </h2>
));
register_sidebar(array('name'=>'sidebar2',
'before_widget' => '<div id="%1$s">', // Removes <li>
'after_widget' => '</div>', // Removes </li>
'before_title' => '<h3>', // Replaces <h2>
'after_title' => '</h3>', // Replaces </h2>
));
register_sidebar(array('name'=>'sidebar3',
'before_widget' => '<div id="%1$s">', // Removes <li>
'after_widget' => '</div>', // Removes </li>
'before_title' => '<h3>', // Replaces <h2>
'after_title' => '</h3>', // Replaces </h2>
));
register_sidebar(array('name'=>'sidebar4',
'before_widget' => '<div id="%1$s">', // Removes <li>
'after_widget' => '</div>', // Removes </li>
'before_title' => '<h3>', // Replaces <h2>
'after_title' => '</h3>', // Replaces </h2>
));
?>

Step 2

In your theme, place the Example Code 2 wherever you want the widgets to appear. They do not have to be in the sidebar. They can be in the footer, the header, home page, Anywhere in any template file. Make sure the name of the widget block matches whatever name you enter above. For example, if you define a widget block as ‘Footer’, then you must also edit ‘sidebar1’ code in this example to ‘Footer’. It is case sensitive.

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

Tags


You may also like

Force cPanel Password Reset

Force cPanel Password Reset
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Get in touch

Name*
Email*
Message
0 of 350