# Add Schema.org Structured Data to a Wagtail Site

Yes. An agent adds JSON-LD for your recipe and blog pages, built from your Wagtail models and StreamField blocks, with tests, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-structured-data/wagtail/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads how the site already describes pages to crawlers. In a Wagtail site shaped like wagtail/bakerydemo, `bakerydemo/templates/base.html` emits a canonical link and Open Graph tags from `page.full_url`, `page.seo_title`, `page.search_description` and `page.image`, with `{% wagtail_site as current_site %}` giving the site name, and `bakerydemo/base/tests/test_seo.py` already asserts those tags with `WagtailPageTestCase`. There is no JSON-LD anywhere. `requirements/base.txt` pins `wagtail>=8.0,<8.1` on `Django>=6.0,<6.1`, `.github/workflows/ci.yml` runs `ruff format --check`, `ruff check`, `curlylint` and `djhtml --check` through `make lint-server`, then `./manage.py check`, `makemigrations --check --noinput` and `./manage.py test` with `bakerydemo.settings.test`.

It then maps the page models to schema.org types. `RecipePage` in `bakerydemo/recipes/models.py` has `date_published`, `subtitle`, `introduction`, a `recipe_headline` rich text field and a `body` StreamField of `RecipeStreamBlock`, whose `ingredients_list` is a `ListBlock` of rich text and whose `steps_list` is a `ListBlock` of `RecipeStepBlock` with a `text` and a `difficulty`; `authors()` returns live `Person` snippets with `first_name` and `last_name`. That becomes a `Recipe` with `name`, `description`, `datePublished`, `author` as `Person` entries, `recipeIngredient` from the ingredients block with the rich text tags stripped, `recipeInstructions` as `HowToStep` items from the steps block, and `image` from the first `image_block` in `body` or `backstory` rendered through a rendition. `BlogPage` in `bakerydemo/blog/models.py`, with `introduction`, `image`, `date_published`, `tags` and its own `authors()`, becomes a `BlogPosting` with `headline`, `keywords` and `publisher` set to the site name.

The data lives on the models, not in the templates. The agent adds a `get_structured_data()` method to `RecipePage` and `BlogPage` that returns a plain dict, and a `structured_data` template tag in a new `bakerydemo/base/templatetags/seo_tags.py` that serialises it with `json.dumps` and escapes `<` so a `</script` in a step cannot break out of the tag. `base.html` gets an empty `{% block structured_data %}` in `<head>`, and `recipes/recipe_page.html` and `blog/blog_page.html` fill it with one `<script type="application/ld+json">`. Pages without the method render nothing new, so `home_page.html` and the bread and location templates are untouched, and no model field changes, so `makemigrations --check` stays clean.

Tests follow `test_seo.py`: a `WagtailPageTestCase` that creates a `Site`, a `RecipeIndexPage` under the root and a `RecipePage` whose `body` is built with `RecipeStreamBlock().to_python()` from a list of ingredients and steps, publishes it, fetches `page.url` and parses the script's contents with `json.loads`, asserting `@type`, the ingredient count, the `HowToStep` count and the author's name; a second case does the same for a `BlogPage` with tags, and a third checks that a page with no image emits no `image` key rather than an empty string. The agent runs `make lint-server`, `./manage.py check`, `./manage.py makemigrations --check --noinput` and `./manage.py test` exactly as `ci.yml` does, and opens a published recipe in its browser to paste the page source into the schema.org validator.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add schema.org structured data to this Wagtail site and open a pull request. Read bakerydemo/templates/base.html, bakerydemo/base/tests/test_seo.py, bakerydemo/recipes/models.py, bakerydemo/recipes/blocks.py, bakerydemo/blog/models.py, bakerydemo/base/models.py, bakerydemo/templates/recipes/recipe_page.html, bakerydemo/templates/blog/blog_page.html, Makefile and .github/workflows/ci.yml first. Add a get_structured_data() method to RecipePage returning a Recipe dict with name, description, datePublished, author entries from authors(), recipeIngredient from the ingredients_list block with rich text tags stripped, recipeInstructions as HowToStep items from the steps_list block, and image from the first image block rendered as a rendition when there is one. Add the same method to BlogPage returning a BlogPosting with headline, description, datePublished, author, keywords from the tags, image and publisher set to the site name. Add a structured_data template tag in bakerydemo/base/templatetags/seo_tags.py that serialises the dict with json.dumps and escapes < so the script cannot be closed early. Add an empty structured_data block to base.html and fill it in recipe_page.html and blog_page.html with one application/ld+json script. Do not add model fields. Write tests in bakerydemo/recipes/tests/ and bakerydemo/blog/tests/ in the style of test_seo.py that render a published page, parse the JSON and assert the type, counts and author, plus one page without an image. Run make lint-server, ./manage.py check, ./manage.py makemigrations --check --noinput and ./manage.py test with bakerydemo.settings.test and paste the output in the pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request with `get_structured_data()` on `RecipePage` and `BlogPage`, the new `bakerydemo/base/templatetags/seo_tags.py`, a one-line block in `base.html`, a block override in `recipe_page.html` and `blog_page.html`, and two new test modules. The description shows the JSON-LD rendered for one recipe and one blog post in the sandbox, and the output of the lint, check, migration-check and test commands.

The CI workflow runs the same lint and test jobs on the pull request, so `djhtml` and `curlylint` have passed on the changed templates and `ruff` on the new Python before a reviewer opens it. No migration is added, which `makemigrations --check` confirms.

A reviewer checks that the ingredient and step text comes out as plain strings rather than rich text HTML, that a draft author is left out because `authors()` filters on `person__live=True`, that a page with no image emits no `image` key, that the escaping of `<` holds for a step containing a closing script tag, and that the schema.org validator in the browser accepts the output. Then they merge and watch the search console for the new rich result types.

## Run it on every new page type

Each time a page model is added, say a `BreadPage` that should describe itself as a `Product`, start one run with `POST /o/{org}/sessions`, this prompt narrowed to the new model and the repository in `resources`. The agent reads the model's fields and the template, adds the method and the block override, writes the test, and opens a pull request for that type alone.

For a team tracking the work in Linear, an automation in the Project with this prompt and a `linear` trigger on `linear.issue.labeled` runs when an issue such as "recipes need Recipe JSON-LD" gets the label; the trigger appends the issue after the prompt and fills in no placeholder, so the agent reads which page type to cover from the issue text, up to the automation's `max_runs_per_hour`.

## Why run it on Rush?

Structured data is easy to write and easy to get subtly wrong: rich text leaking into `recipeIngredient`, a step containing a closing script tag, an author in draft appearing in the output. In a Rush sandbox the agent renders real pages from real StreamField values, parses the JSON back in a test, and opens the page in its own browser to run the validator, with every command and its output kept in the transcript.

The result passes the repository's own gates, `ruff`, `curlylint`, `djhtml`, `check`, `makemigrations --check` and the test suite, before a reviewer opens it, and it adds no migration, so there is nothing to coordinate on deploy. The same request works for any Wagtail site whose page models carry the fields schema.org asks for.

## Frequently asked questions

### Why put the data on the model rather than in the template?

Because the template language is the wrong place to strip rich text, pick the first image block out of a StreamField or format a date. A `get_structured_data()` method is plain Python that a test can call directly, and the template tag only serialises and escapes. The Open Graph tags in `base.html` stay as they are.

### Does it change the Wagtail API output?

No. The `api_fields` on `RecipePage` and `BlogPage` and the router in `bakerydemo/api.py` are untouched. If a headless frontend should receive the same dict, ask for it as an extra `APIField` in the prompt and the agent adds it with a serializer.

### What about pages with no date or no author?

`date_published` is nullable on both models and `authors()` can be empty, so the method leaves `datePublished` or `author` out rather than emitting `null` or an empty list, and the tests cover the no-image case the same way. The validator accepts a `Recipe` with those keys missing; a search engine simply has less to show.

### Which schema.org types does it cover?

`Recipe` for `RecipePage`, with `HowToStep` instructions, and `BlogPosting` for `BlogPage`. Breads, locations, the gallery and the form page get nothing in this pull request; each would need its own mapping, which is a one-model follow-up with the same prompt.

## More Wagtail jobs

- [Add Type Hints to a Wagtail Codebase](https://getrush.ai/run/add-type-hints/wagtail/)
- [Add a New Page Type to a Wagtail Site from a Linear Issue](https://getrush.ai/run/add-workshop-page/wagtail/)
- [Fix N+1 Queries in a Wagtail Site](https://getrush.ai/run/fix-n-plus-one-queries/wagtail/)

## The same job on other stacks

- [Add JSON-LD Structured Data to a Zola Site](https://getrush.ai/run/add-structured-data/zola/)
- [Add JSON-LD Structured Data to an Eleventy Blog](https://getrush.ai/run/add-structured-data/eleventy/)
- [Add Structured Data to a Gatsby Blog](https://getrush.ai/run/add-structured-data/gatsby/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
