// Creating the widget
class wpb_widget extends WP_Widget {
function __construct() {
parent::__construct(
// Base ID of your widget
‘wpb_widget’,
// Widget name will appear in UI
__( ‘Opinion Widget’, ‘textdomain’ ),
// Widget description
[
‘description’ => __( ‘Sample widget based on WPBeginner Tutorial’, ‘textdomain’ ),
]
);
}
// Creating widget front-end
public function widget( $args, $instance ) {
$title = apply_filters( ‘widget_title’, $instance[‘title’] );
// before and after widget arguments are defined by themes
echo $args[‘before_widget’];
if ( ! empty( $title ) ) {
echo $args[‘before_title’] . $title . $args[‘after_title’];
}
// This is where you run the code and display the output
echo __( ‘Hello, World!’, ‘textdomain’ );
echo $args[‘after_widget’];
}
// Widget Settings Form
public function form( $instance ) {
if ( isset( $instance[‘title’] ) ) {
$title = $instance[‘title’];
} else {
$title = __( ‘New title’, ‘textdomain’ );
}
// Widget admin form
?>