Reading view

Put an LLM chat on a WP site without a plugin — 481 bytes in the page, everything else external

This sub gets the "how do I add AI chat to my site" question constantly and the answer is usually a plugin that wants an API key in the WP database. Here's the version I ended up with instead, in case it's useful to anyone else.

What's actually in WordPress: one block, 481 bytes. It sets an endpoint URL on window and injects a script tag. That's it. No plugin installed, nothing in the database, no key stored in WP.

Everything else lives in one external serverless file. It serves the widget itself from a /widget.js route, so the ~19KB of markup, styles and logic never enters WP content at all. The API key is an env var on that service. Shipping a widget change is one external deploy — I don't touch the site.

Three WP-specific things that cost me time:

  • Scripts inside an HTML block get escaped at render time, and the failure is silent. Stored content stays byte-clean while the live page does nothing and the console is empty. Always check the rendered output rather than what the editor saved.
  • Ampersands in inline script text were a repeat offender for the same reason. Keeping the injected block down to 481 bytes with no logic in it sidesteps the whole class.
  • A block appended next to another does not inherit the page wrapper. Anything you insert needs to constrain its own width or it renders indented against everything else.

If a page is still classic/freeform, block-level edits refuse to target it and you're looking at a full-content rewrite. What worked better for me was editing through the REST API from the browser console on wp-admin — read the raw content, do a targeted string replace, POST it back. Surgical, no conversion needed, and the content never round-trips through a copy step.

Result: https://dhseadev.online/ask/ Full build notes: https://dhseadev.online/2026/08/06/ai-answers-desk-val-town-groq/

submitted by /u/DHSeaDev
[link] [comments]
  •  
❌