Using WordPress Dynamic Component

In this lesson, I will show you how we create dynamic components and how we use them.

First, open your functions.php file in the theme you are using.

How to Add Dynamic Component?

We will create the component with the register_sidebar() function by creating a function. We will also hook our widgets_init function.

function register_widgets()
{
    register_sidebar([
        'name' => 'Archive Sidebar',
        'id' => 'archive_sidebar',
        'before_widget' => '<div class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>'
    ]);
}

How to Use Dynamic Component in Theme?

Just write the following codes on the page you want to show;

if (is_active_sidebar('archive_sidebar')){
    dynamic_sidebar('archive_sidebar');
}
Comments

There are no comments, make the firs comment