Possible to preset a widget’s contents via a plugin script?

There are a few mistakes in your code:

  1. You need to specify the instance ID manually, for eg. 2. If you want to append a text widget, and not overwrite the sidebar’s contents, then try using $id = count($opts)+1, or you could just generate a random ID.

  2. Use the widget_ID_base-instance_ID in $sidebars_widgets[$sidebar_id] = "widget_text-".$id;, and put that inside a array:

    $sidebars_widgets[$sidebar_id] = array("text-".$id);

Leave a Comment