wowprompt

WordPress shortcode with escaped output and cached results

Writes a custom shortcode as a small plugin, with sanitised attributes, escaped output, a transient cache for anything slow and a short usage guide for editors. Use it when a site needs a reusable block of dynamic content, such as a price table, a list of latest items or a store timing box, without a heavy page builder add-on.

A complete small plugin file with a shortcode, sanitised attributes, escaped HTML, a cache with expiry and examples of use in a post
The output this prompt produced, unedited.

The prompt

Fill in these first

  • What the shortcode shows: [e.g. today's store timings and a closed-on-holidays notice]
  • Shortcode name and attributes: [e.g. store_hours with branch and style]
  • Where the data comes from: [e.g. a custom post type, an options page, a remote JSON feed]
  • How fresh it must be: [e.g. refresh every 30 minutes]
  • PHP and WordPress versions on the site: [paste]

Template to complete

Plugin header

Name, description, version and text domain.

Attribute handling

Defaults with shortcode_atts, then each attribute sanitised for its type.

Data fetch

The query or remote request, wrapped in a transient with the chosen expiry, and a clear failure path.

Output

Markup built with escaping on every value, returned as a string and never echoed.

Usage

Three examples an editor can paste, with what each shows.

Rules

  • Escape late: esc_html, esc_attr and esc_url at the point of output.
  • Prefix every function and option name to avoid clashes.
  • No SQL built by joining strings; use prepared queries if a direct query is needed.
  • The page still renders if the data source is down.
wordpress shortcodecustom shortcode pluginwordpress developmentoutput escapingtransient cachephp plugin

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity