Today I will discuss about how to add widget support in your wordpress theme. It is very useful for showing content like post list or pages or your desired content in your desired locations. It must be used in any kind of wordpress site.

It is very easy to add a widget support in wordpress. Just few steps you have to complete.

Add the following code in your functions.php

function shareideas_theme_widgets() {
'name' => 'Why Us',
'id' => 'why_us',
'class' => 'why_us',
'description' => 'Use this widget for your site why us content',
'before_widget' => '<div class="col-md-6 col-sm-6"><div class="why-us">',
'after_widget' => '</div></div>',
'before_title' => '<h1>',
'after_title' => '</h1>'
add_action('widgets_init', 'shareideas_theme_widgets');

Here register sidebar is a wordpress function you can give a name and you can give a id name. Then giva a description. Then write what will be in the before widget and the after widget and add a title tag.

In next step you will have to add the following code in your required place. Where you want to show the widget.

<?php dynamic_sidebar('id_name_here'); ?>

Here write your sidebar id name here.


If you have any question feel free to ask. For more details see this video. I have done it here

Useful Tags :