Mika MAtikainen
Apr 15, 2020 · 4 min read
Widget Initialization
[code lang=”php”]
function create_my_widget() {
register_sidebar(array(
‘name’ => __( ‘My Sidebar’, ‘mytheme’ ),
‘id’ => ‘my_sidebar’,
‘description’ => __( ‘The one and only’, ‘mytheme’ ),
));
}
add_action( ‘widgets_init’, ‘create_my_widget’ );
[/code]
Creating a widget is a very simple and common action to add to a theme or plugin. When you do so, you have to hook into the widget_init action. This hook lets you run your code when widgets are being generated within WordPress, so it’s the perfect hook to add your own widgets at the same time.