Skip to content

Read and Update Block Theme Templates with AI ​

Use Easy MCP AI to find and update templates in your active block theme. Read a template before changing it, because an update replaces its entire content.

In this article

Before you start ​

Your site must have an active block theme, and the WordPress user connected to your AI client must have the edit_theme_options capability. A capability is a WordPress permission; this one allows the user to edit theme options and templates.

If wp_update_template is disabled, an administrator can enable it:

  1. In WordPress, go to Easy MCP AI > Tools.
  2. Search for wp_update_template and enable it. If a deployment lock prevents you from changing it, ask the person who manages your site's deployment settings to unlock it.
  3. Click Save changes. If your AI client still does not list the tool, refresh its tool list.

Read and update a template ​

  1. Ask your AI client to call wp_list_templates and find the template you want to change. The result includes the template's id; use that value exactly as returned.
  2. Ask it to call wp_get_template with that id as template_id. Keep the matching type: template is the default for regular templates, and template_part is for headers, footers, and other reusable areas.
  3. Review the current content returned by wp_get_template before making a change. Then ask your AI client to call wp_update_template with the same template_id, the matching type, and the complete content you want the template to have.

The content sent to wp_update_template replaces the template's entire content; it does not change just the part you edited. Include everything that should remain in the template, not only the new or changed section.

Use template IDs exactly ​

A template ID has this format:

text
theme-slug//template-slug

The theme part can include dots and at most one parent folder. For example, my.theme//index and agency/acme//index are valid formats. Each theme folder can contain only ASCII letters, numbers, dots, hyphens, and underscores, and cannot start with a dot. The final template slug can contain only ASCII letters, numbers, hyphens, and underscores.

Percent-encoded slugs are rejected; do not decode or rewrite them. IDs with deeper theme paths, such as a/b/c//index, are also rejected. Do not try to repair an invalid ID: changing it can make it identify a different template.

Was this helpful?