|

How to add widget support to your WordPress Theme

Widget Support to your WordPress Theme

Today i will explain very easy how to add widgets support to your WordPress Theme.

So we need to start with your functions.php file and add some lines to start suport widgets in your theme.

First go to your theme dashboard  got Apperance  – > Widgets.

If you don`t have widgets in right side of your Widgets Dashboard, you should add some widgets in your theme.

The Simplest way is to add these lines in your WordPress Theme functions.php file:

function arphabet_widgets_init() {

	register_sidebar( array(
		'name' => 'Home right sidebar',
		'id' => 'your_id_for_sidebar',
		'before_widget' => '<div>',
		'after_widget' => '</div>',
		'before_title' => '<h2 class="rounded">',
		'after_title' => '</h2>',
	) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );

And of course you need to display this widget in your Theme. You Should add php code to your themplate to be able to display your widget with sample code like this:

<?php if ( dynamic_sidebar('your_id_for_sidebar') ) : else : endif; ?>

Now your Theme should have Widget Support and you will be able to display content in your sidebar which you add above

Related Articles

Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *