class My_Widget extends WP_Widget { public function __construct() { parent::__construct( 'my_widget', // Widget ID 'My Widget', // Widget name array('description' => 'A custom widget that displays my content') // Widget description ); } public function widget($args, $instance) { // Output widget content echo "Hello, World!"; } } function register_my_widget() { register_widget('My_Widget'); } add_action('widgets_init', 'register_my_widget');In this example, we define the `My_Widget` class that extends the `WP_Widget` class. We define the widget ID, name, and description using the constructor. The `widget` method is used to output the widget content. Finally, we register the widget using the `register_widget` function and add it to the widgets area using the `widgets_init` action hook. This code example is using the PHP language and is part of the WordPress package library.