Testing wideget

[sourcecode language=”csharp”]
01
// Register and load the widget
02
function wpb_load_widget() {
03
register_widget( ‘wpb_widget’ );
04
}
05
add_action( ‘widgets_init’, ‘wpb_load_widget’ );
06

07
// Creating the widget
08
class wpb_widget extends WP_Widget {
09

10
function __construct() {
11
parent::__construct(
12

13
// Base ID of your widget
14
‘wpb_widget’,
15

16
// Widget name will appear in UI
17
__(‘WPBeginner Widget’, ‘wpb_widget_domain’),
18

19
// Widget description
20
array( ‘description’ => __( ‘Sample widget based on WPBeginner Tutorial’, ‘wpb_widget_domain’ ), )
21
);
22
}
23

24
// Creating widget front-end
25

26
public function widget( $args, $instance ) {
27
$title = apply_filters( ‘widget_title’, $instance[‘title’] );
28

29
// before and after widget arguments are defined by themes
30
echo $args[‘before_widget’];
31
if ( ! empty( $title ) )
32
echo $args[‘before_title’] . $title . $args[‘after_title’];
33

34
// This is where you run the code and display the output
35
echo __( ‘Hello, World!’, ‘wpb_widget_domain’ );
36
echo $args[‘after_widget’];
37
}
38

39
// Widget Backend
40
public function form( $instance ) {
41
if ( isset( $instance[ ‘title’ ] ) ) {
42
$title = $instance[ ‘title’ ];
43
}
44
else {
45
$title = __( ‘New title’, ‘wpb_widget_domain’ );
46
}
47
// Widget admin form
48
?>
49

50