Skip to main content
Glama

Add a widget

wp_add_widget
Destructive

Adds 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

NameRequiredDescriptionDefault
id_baseYesWidget type base, e.g. "text", "nav_menu", "block", "search". Must be a registered type; the refusal lists the available ones.
sidebarYesTarget sidebar id as wp_list_sidebars lists it, e.g. "sidebar-1", or "wp_inactive_widgets".
positionNoOptional 0-based insert position within the sidebar; appended by default. Negative values count as 0.
settingsNoInitial settings for the new instance: text, numbers, true, false, null or flat lists. Optional; omitted means no settings.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv4.10.0

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Goes well beyond the annotations by disclosing the sanitisation path (the widget's own update() plus widget_update_callback), the capability-dependent HTML filtering, the exact refusal conditions where "nothing is saved", and that no undo point is created. Annotations already flag destructive/non-idempotent, and the description reinforces rather than repeats them.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Four tight sentences, front-loaded with the action and target, then behavior, then failure modes, then the undo caveat. No filler and no repetition of the title.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Although there is no output schema, the description names the return shape (added, id in "<id_base>-<number>" form, sidebar), covers rejection behavior, and states the atomics of the write. That is everything needed to call a mutation tool with four parameters correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3; the description still adds real meaning by explaining what happens to the settings object (widget-specific sanitisation and filtering) and by clarifying that sidebar can be wp_inactive_widgets. It adds little about position beyond what the schema already states.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Opens with a specific verb+resource+scope: "Add a new widget of a registered type to a sidebar, or to wp_inactive_widgets." It also names the sibling that handles the adjacent case (wp_update_widget for existing widgets), so an agent can route without opening either schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly says existing widgets are handled by wp_update_widget, which is a clean alternative-routing rule, and warns that no undo point is recorded. It doesn't tell the agent to check wp_list_sidebars/wp_get_widgets first, but the schema fields cover the sidebar-id source.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools