Specifying the widget locations

In the function.php file, underneath the add_action function, we will specify the locations. For this, we will add a function called init_widgets, pass in &id, and then add register_sidebar as shown here:

// Widget Locations
function init_widgets($id){
register_sidebar();
}

The register_sidebar function is used for creating any kind of widget position. Even though it says sidebar, it doesn't have to be in the sidebar; in our case, it is but it doesn't have to be.

Next, we will pass in an array to the register_sidebar function. Add a name, Sidebar, and an ID, sidebar, as shown here:

  register_sidebar(array(
'name' => 'Sidebar',
'id' => 'sidebar'
));
}

Then we will declare the action using add_action. The hook we will use is widgets_init and put in the function we just created, which is init_widgets, as shown here:

add_action('widgets_init', 'init_widgets');

Next, we will register the widgets.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.21.158