Prevent second widget activation

You can create a one-time-use widget with the following example found here: wp_register_sidebar_widget

The following code will create a widget called “Your Widget” which will become available in the WordPress Administrative Panels. The widget can then be dragged to an available sidebar for display.

Note that this widget can only be used once in exactly 1 of the
sidebars. For recursive widgets (widgets you can add to multiple times
and add to multiple sidebars) please see the Register Widget function.

function your_widget_display($args) {
   extract($args);
   echo $before_widget;
   echo $before_title . 'My Unique Widget' . $after_title;
   echo $after_widget;
   // print some HTML for the widget to display here
   echo "Your Widget Test";
}

wp_register_sidebar_widget(
    'your_widget_1',        // your unique widget id
    'Your Widget',          // widget name
    'your_widget_display',  // callback function
    array(                  // options
        'description' => 'Description of what your widget does'
    )
);

Leave a Comment