Add a widget
wp_add_widgetAdds a new widget of a registered type to a sidebar or to wp_inactive_widgets. Refuses unknown types, invalid sidebars or rejected settings, so nothing is saved.
Instructions
Add a new widget of a registered type to a sidebar, or to wp_inactive_widgets. Returns added, id (the new "<id_base>-") and sidebar. Settings pass the widget's own update() sanitisation and the widget_update_callback filter, the same as the widgets screen — so HTML is filtered unless the account may post unfiltered HTML. An unknown type or sidebar, or settings the widget rejects, are refused and nothing is saved. Existing widgets are changed by wp_update_widget; no undo point is recorded.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id_base | Yes | Widget type base, e.g. "text", "nav_menu", "block", "search". Must be a registered type; the refusal lists the available ones. | |
| sidebar | Yes | Target sidebar id as wp_list_sidebars lists it, e.g. "sidebar-1", or "wp_inactive_widgets". | |
| position | No | Optional 0-based insert position within the sidebar; appended by default. Negative values count as 0. | |
| settings | No | Initial settings for the new instance: text, numbers, true, false, null or flat lists. Optional; omitted means no settings. |