Skip to content
PHP

Hot to Register Widget in WordPress by Hook

A
Author
Jun 8, 2021 · 1 min read
Hot to Register Widget in WordPress by Hook

To register a widget in WordPress using a hook, you can use the widgets_init hook. Here’s an example code snippet that demonstrates how to register a custom widget:

add_action( 'widgets_init', 'my_register_sidebar' );

function my_register_sidebar(){
 register_sidebar(array(
 'name' => 'My new sidebar',
 'id' => 'your-sidebar-id',
 'description' => 'My sidebar description',
 'before_widget' => '<aside id="%1$s" class="widget group %2$s">',
 'after_widget' => '</aside>',
 'before_title' => '<h3 class="widget-title">',
 'after_title' => '</h3>',
 ));
}
A
Author

Author at The Creative Coders.

The monthly build log

One email a month. New posts, lessons, and the occasional strong opinion. No spam.