Hello friends!! In this short tutorial I am going to explain how easily you can create a dynamic widget in a admin interface of wordpress and call it directly into you template file. So basically with this tutorial you will know how to add dynamic widget into template.
First we have to register a dynamic widget in to the wordpress admin interface. To know where the register dynamic sidebar are located follow the below lines.
To register a dynamic widget into your wordpress dashboard.
function new_widgets_init() {
register_sidebar(array(
'name' => __('Footer Slogan', 'theme_name'),
'description' => __('Footer slogan text area', 'theme_name'),
'id' => 'foo_slogan',
'before_title' => '
',
'before_widget' => '
'
));
}
add_action('widgets_init', 'new_widgets_init');
Note: If you are using a child theme you should not match the function of register sidebar to the parent theme. It should be different one.
Just to know how to add dynamic widget into template follow the below code. Go to your template and paste the code.
<?php if ( is_active_sidebar( 'foo_slogan' ) ) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'foo_slogan' ); ?>
</div>
<?php endif; ?>
Thanks for reading the tutorial