Widget area is a part of our WordPress themes structure where we can add more widgets as we need. Here we give you some basic knowledge about how to register a wordpress widget area. We can create wordpress widget area in a header area of website, in footer area of website or in the middle of any post and where you want to add wordpress widget area in your personal blogging themes. Most of the time sidebar is used to add wordpress widget area. In many websites widgets also used in footer, header and main content area. This example uses the Sidebar template (sidebar.php).


You May Also Like:


Learn How to Register a wordpress widget area

First you define the sidebar in your theem. To register a widget, you need to add the register_sidebar function to the Theme Functions template (functions.php).

To add a Widget Go to Appearance > Widgets and Drag a Widget to a Widget Area.Here you can add available Widgets.

main

Registering a Widget Area

Add following code in your theme’s functions.php file.

<?php
/**
 * Register Widget Area.
 *
 */
function wpgyan_widgets_init() {

	register_sidebar( array(
		'name' => 'Header Sidebar',
		'id' => 'header_sidebar',
		'before_widget' => '<div>',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="rounded">',
		'after_title' => '</h2>',
	) );
}
add_action( 'widgets_init', 'wpgyan_widgets_init' );
?>

 

  • name:This name is unique to the widget and appears on the Widgets page on the Dashboard; this name is helpful if you register several widgetized areas on your site.
  • id:This is the unique ID given to the widget.
  • before_widget:This is the HTML markup that gets inserted directly before the widget; it’s helpful for Cascading Style Sheets (CSS) styling purposes.
  • after_widget:This is the HTML markup that gets inserted directly after the widget.
  • before_title:This is the HTML markup that gets inserted directly before the widget title.
  • after_title:This is the HTML markup that gets inserted directly after the widget title.

By using this code your theme recognize that you have registered a widget area for your theme and make the widget area easy for you to and drop widgets into from the Widgets page on the Dashboard.

Oblivion Magazine - Responsive Tumblr Template

You can mange widget area by using this plugin Sidebar & Widget Manager for WordPress.

About The Author

Related Posts

Leave a Reply

Your email address will not be published.