While designing WordPress, we are often limited by the theme developers ideas and we need to expand WordPress based on our clients requirements.
A quick and easy way is to use Dynamic Sidebars (Widgets). Once you create specific sidebars, you will be able to insert it where you want and extend the design of WordPress.
For this article we assume that Footer area needs to be expanded, you can use this same method to expand any section or parts of your WordPress (header, body, etc).
Step 1: Register Sidebar
First, you must register the sidebar into theme function page. Location is wp-content/themes/youtheme
Add the following code to the (end of the page is better) functions.php file in your theme. We recommend
if ( function_exists('register_sidebar') )
register_sidebar( array(
'name' => __( 'My Custom Sidebar'),
'id' => 'my-custom-sidebar',
'description' => __( 'An optional widget area for your site footer' ),
'before_widget' => '<div class="widget-content">',
'after_widget' => "</div>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
After added and save the functions.php file you can see them from Appearance -> Widgets.
Step-2 : Add the sidebar into the theme to display it
I want to render the custom sidebar in footer only, so I’ll edit the footer.php file.
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('my-custom-sidebar')) : ?>
<?php dynamic_sidebar( 'my-custom-sidebar' ); ?>
<?php endif; ?>
That’s it. You can add widget to check the results.
Leave a reply