How to create widget areas – Advanced users

If you are an advanced user who has a little coding knowledge you can create your custom widget areas by very simple code.

Basically there two steps you need to take:

  • register your custom widget area in functions.php
Here is the code you can use:
<?php $args = array(
	'name'          => sprintf(__('Sidebar %d'), $i ),
	'id'            => 'sidebar-$i',
	'description'   => '',
	'before_widget' => '<li id="%1$s">',
	'after_widget'  => '</li>',
	'before_title'  => '<h2>',
	'after_title'   => '</h2>' ); ?>
<?php register_sidebar( $args ); ?>

 

  • use your already registered custom widget area in a template file
Here is function call example:
<?php dynamic_sidebar( 'Sidebar N' );  ?>

It is not a bad idea to check  if the side bar is active (in use):

<?php if ( is_active_sidebar('Sidebar N') ) { .... }  ?>

 

You might want to try a plugin for creating custom widget areas.

Hey, like this? Why not share it with a buddy?

Stay tuned

Follow updates, new products and useful information

No comments yet.

Leave a Reply