Create A Widget Area On Any WordPress Page

Create a new widget area in any WordPress theme in two steps. It’s very easy to do once you understand the concepts.

Add this code to functions.php in your WordPress theme folder:


<?php
/**
 * Register Widget Area.
 *
 */
function kustom_widgets_init() {
 
	register_sidebar( array(
		'name' => 'My Kustom Widget',
		'id' => 'kustom_widget',
		'before_widget' => '<div>',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="widget_before_title">',
		'after_title' => '</h2>',
	) );
}
add_action( 'widgets_init', 'kustom_widgets_init' );
?>

2. Add this code to the page template in the area you want the widget to appear:


<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('kustom_widget') ) : 
 
endif; ?>

Now go to your admin area in the Widgets section and you’ll see your new widget area named “My Kustom Widget”.

Tweet It. Share It.

See more Uncategorized