Blog for web designers

How to add dynamic widget into template

How to add dynamic widget into template

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.

Register a dynamic widget into your wordpress dashboard.

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.

  • Login to your dashboard
  • Go to Appearence tab on the left hand side.
  • Click on Widget tag under the Appearence tab.

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' => '
', 'after_title' => '
', 'before_widget' => '
', 'after_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.

How to add dynamic widget into template

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 🙂

Santosh Shah

My name is Santosh Shah and blogs at santosh-shah.com


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.