It appears that wp_register_sidebar_widget
is a very outdated function from early implementations of widgets. Apparently back then widgets could only be used once each and the output callback name seems to be what made a widget unique, despite the existence of an ID. The single-use nature of these widgets doesn’t appear to be an intentional feature.
Given it’s age I would suggest using the newer API, based on register_widget()
. To register 3 widgets with the same output you would create a class for the widget, with some additionaland register 3 different instances of it.
function wpse_292985_widget_display( $args ) {
echo '<p>' . $args['widget_name'] . '</p>';
}
class WPSE_292985_Widget extends WP_Widget {
function __construct( $id, $name, $widget_ops ) {
parent::__construct( $id, $name, $widget_ops );
}
function widget( $args, $instance ) {
wpse_292985_widget_display( $args );
}
}
function wpse_292985_register_widgets() {
register_widget( new WPSE_292985_Widget(
'first',
'First Widget',
['description' => 'This is the first widget.']
) );
register_widget( new WPSE_292985_Widget(
'second',
'Second Widget',
['description' => 'This is the second widget.']
) );
register_widget( new WPSE_292985_Widget(
'third',
'Third Widget',
['description' => 'This is the third widget.']
) );
}
add_action( 'widgets_init', 'wpse_292985_register_widgets' );
The first thing happening there is defining the function we want the widget to output. It accepts $args
as an argument which we’ll pass through in our widget class.
The next bit is the class for the Widget. This class is just a copy of the generic WordPress widget class, but we’re setting the widget()
method here to output our function.
Then we register 3 widgets by creating new instances of our widget class and passing them into register_widget()
.