Experimental. It relies on third-party AI providers — review their pricing and privacy terms, and check generated content and code before you publish it.
The AI Assistant works in two places:
- In the block editor — a WP Coder AI panel that writes or translates the text of the blocks on a page.
- In the snippet editor — a Generate with AI panel that writes a snippet’s HTML, CSS, JS and PHP from one description.
Your API key stays on the server: the browser sends the prompt to WP Coder, and WP Coder calls the provider.
Setting it up#
The AI Assistant is off by default: without it, the AI tab and both panels are not shown. To make it available, add this line to wp-config.php (above “That’s all, stop editing!”):
define( 'WPCODER_ENABLE_AI', true );
Then Tools → AI → Enable AI Assistant, and:
| Field | Notes |
|---|---|
| Provider | OpenAI, Anthropic (Claude), Google (Gemini), or Custom (OpenAI-compatible). |
| URL | Custom provider only — the base URL ending in /v1 (see below). |
| API Key | Your key from the provider. |
| Model | Optional for the three hosted providers, required for Custom. |
Default models when Model is empty:
| Provider | Default model |
|---|---|
| OpenAI | gpt-4o-mini |
| Anthropic (Claude) | claude-haiku-4-5-20251001 |
| Google (Gemini) | gemini-2.0-flash |
Click Test Connection — a green Connected! means the provider, key and model work.
To use AI in the snippet editor too, also turn on AI in the snippet editor.
Custom (OpenAI-compatible) providers#
Use Custom for any server that speaks the OpenAI chat-completions API — Ollama, vLLM, LiteLLM, LocalAI or a hosted gateway.
- URL — the base URL, e.g.
https://example.com/v1orhttp://localhost:11434/v1for Ollama./chat/completionsis added for you; pasting the full…/v1/chat/completionsworks too. - API Key — sent as
Authorization: Bearer <key>. - Model — the exact model id the server exposes, e.g.
qwen2.5-coder:14b.
WP Coder sends only model and messages and reads the answer from choices[0].message.content. Settings such as temperature are not sent.
In the block editor — WP Coder AI#
The WP Coder AI panel is in the editor’s settings sidebar, on the Post / Page tab (next to Status, Excerpt and the other document panels).
- Write an Instruction — what the content is about (“web design studio, services page”) or what to do with it (“translate to Ukrainian”). Empty means “write suitable content for each field”.
- Tick Selected block only to work on the block you have selected; otherwise every block on the page is processed.
- Click Apply AI. Long pages are sent in batches, with progress shown on the button. The text is written straight into the blocks — review it, and use Undo if you don’t like it.
What it fills in:
- WP Coder blocks — their Text, Textarea and Rich Text fields, including those inside a Repeater. Other field types (images, URLs, colours…) are left alone.
- Standard blocks — paragraphs, headings, list items, buttons, quotes, verse, preformatted, pullquotes, and image, cover and media-text alt text and captions.
HTML inside the text is kept. If there is nothing to process, the panel says No translatable blocks on this page.
In the snippet editor — Generate with AI#
With AI in the snippet editor on, a Generate with AI panel appears above the code tabs.
- In What should the snippet do?, describe the snippet in one prompt, e.g. “responsive 3-plan pricing table with a hover effect and a monthly/yearly toggle”.
- Under Generate into, tick the tabs the AI may write: HTML, CSS, JS, PHP.
- Generate — one request returns the whole snippet, each part as a card with a preview.
- Tick Apply for the parts you want. Empty tabs are ticked for you; a tab that already holds code is unticked and warns how many lines it would replace.
- Apply selected puts the code into the editors.
Nothing is saved until you Save the snippet — reload or Ctrl/Cmd+Z reverts it. Generated PHP is scanned for forbidden functions (eval, exec…); a card with any shows a ⛔ warning, and such code is blocked when it runs anyway.
Who can use it#
The AI calls are billed to the site owner’s key, so access is deliberately narrow:
| Where | Required capability |
|---|---|
| Block editor (WP Coder AI) | publish_posts — Authors and up. Contributors can’t use it. |
| Snippet editor (Generate with AI) | manage_options — administrators. |
| Settings and Test Connection | Administrators. |
Each user can make 60 requests per 10 minutes, and a single prompt is limited to 50,000 characters.
For developers#
| Filter | Default | Purpose |
|---|---|---|
wow_coder_ai_capability |
see above | Capability for the AI endpoints; receives the default and the context, 'content' or 'snippet'. |
wow_coder_ai_rate_limit |
60 |
Requests per user per window; 0 disables the limit. |
wow_coder_ai_rate_window |
600 |
Window length in seconds. |
wow_coder_ai_max_prompt_chars |
50000 |
Longest accepted prompt. |
To remove the AI features again, delete the WPCODER_ENABLE_AI line from wp-config.php (or set it to false) — the AI tab and both panels disappear; the saved provider settings are kept.
Troubleshooting#
| Symptom | Likely cause |
|---|---|
HTTP 404 |
Wrong URL for a Custom provider — it must be the root that has …/chat/completions under it, usually ending in /v1. |
HTTP 401 / invalid API key |
Wrong or empty API Key. |
HTTP 400 / model not found |
The Model id doesn’t match what the server exposes — copy it exactly. |
| Custom URL is required for the custom provider. | The URL field is empty. |
| Unexpected response: no content in choices | The server isn’t really OpenAI-compatible. |
| Test Connection works, but generating fails | The model didn’t return valid JSON for the generate/translate request — try a more capable model. |
| Too many requests | The per-user limit was reached — wait a few minutes. |
Privacy#
The text you generate or translate is sent to the provider you configure. With a self-hosted server (Ollama, vLLM) it stays on your own infrastructure. The API key is stored in the site’s settings and is never sent to the browser — still, only let trusted administrators reach the Tools page.