Create multiple widgets in wordpress theme

Create multiple widgets in wordpress theme

WordPress tutorial for, In this article we will show, how to Create multiple widgets in wordpress theme. Widgets for very important in wordpress themes and plugins. First I need to tell you this widget api is located in following file.

wp-includes/widgets.php

For enable the sidebar support in wordpress theme you need to register atleast one sidebar in wordpress api. For enabling the side bar you need to just open the functions.php file and put following code in that file.

if ( function_exists('register_sidebar') )
register_sidebar();

This is enable the global sidebar for your wordpress theme.

If you want multiple sidebar in your wordpress theme then use the following code. I created two sidebars in my wordpress theme. First is normal sidebar and second is footer sidebar.

For main sidebar showing just open your sidebar.php file put following code in that file.


if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Main Sidebar') ) :
 endif;

For showing second widget in footer section open your footer.php file and put following code in that file.


if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer Sidebar') ) :
 endif;

Then go to your widget section through admin panel and select your widget which you want to show in widget sections.

Create multiple widgets in wordpress theme
Create multiple widgets in wordpress theme

If you are having any issues or question about using widget in wordpress theme then write to me.

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.