For AI coding agents

Give your agent the rules, recipes, and checks for reliable changes.

Download Markdown
On this page

How an AI coding agent (Claude Code, Codex…) with a shell or HTTP access creates and publishes pages, block theme templates and parts and patterns on a WordPress site that has Jikji. The syntax is in Syntax reference, the helpers in Dynamic data, every command in wp jikji and every route in REST API; this chapter is the procedure and the rules.

11.1 Read this first#

  1. A Jikji document is HTML with j: attributes plus style rows. A save validates and stores it; a published document is compiled to a PHP template and CSS that the front end runs.
  2. A page replaces the content area inside the theme template. A template (block themes only) replaces the whole page, header and footer included.
  3. Save only through Jikji's save path — wp jikji content save on the server, POST /wp-json/jikji/v1/content/<id> remotely. Never write the _jikji_content meta or the files under wp-content/jikji/ directly.
  4. Element IDs come from the server ID pool — wp jikji content save --placeholders turns id="{hero}" into server IDs (or wp jikji ids, POST /elements/ids). One ID style row per name, site-wide.
  5. Class styles are global. wp jikji refuses an existing class sent without baseCss (jikji_class_exists). Use new names, or send baseCss / --update-classes to change one.
  6. Saves use optimistic locking. wp jikji locks on the version at the start of the command; when a person can have the document open in the editor pass content get --field=hash as --base-hash. REST sends the read hash as baseHash.
  7. Publishing is public. A published page or template changes the front end on every save. Hierarchy templates (index, single, single-post…) and theme parts affect the whole site — build as a Jikji draft, verify, then publish. wp jikji requires --yes for those (an agent cannot answer a prompt, so without --yes the command fails).
  8. When done, verify with wp jikji status and a front-end request (11.6). --format=json gives code and data; every failure exits 1.
  9. The editor's AI tab is for people inside the builder. POST /jikji/v1/ai/turn is the editor conversation's gateway, not a model proxy (tool execution is in the browser), and POST /jikji/v1/ai/fetch is the fetch_url tool's endpoint — an agent has no reason to call either. Edits made by the AI tab go through the same save path, validation and revisions (notes AI: …, AI (code): …) and are not distinguishable in the document.

Page or template? A new body only → a page document. A new header/footer, or one frame for several pages → a custom template (+ parts). Together, the template's jikji_post('content', $post) slot shows the page's Jikji body — output the title in only one of them.

11.2 Access paths#

Path When Authentication
A. wp jikji A server shell — preferred: thin commands with the REST routes' validation, permissions and error codes Runs as the site administrator (lowest ID with jikji_compile) unless --user=<login>
B. REST https://<site>/wp-json/jikji/v1/… Remote, HTTP only An application password (curl -u "user:xxxx xxxx xxxx xxxx xxxx xxxx")
C. wp eval-file with the plugin classes A behaviour no command covers (11.9) wp_set_current_user(<admin id>) in the script

Permission: jikji_compile plus edit_post on the target (templates and parts: edit_theme_options, in practice administrators). REST readiness: wp_is_application_passwords_available() true (Wordfence's "Disable application passwords" makes it false — the site owner decides; an agent does not change security settings), the Authorization header reaching PHP (GET /wp-json/wp/v2/users/me?context=edit → 200), /?rest_route=/… when permalinks are off, and the agreed User-Agent when a firewall filters on it.

11.3 Writing rules in short#

  • Put a server ID on every element that has styles or that the editor must handle; one element per block (Syntax 8.1); bindings on block elements, not inside Rich Text markup; no <script> (a Code block exists, but prefer helpers).
  • Attribute values double-quoted, " inside as &quot; — JSON arguments especially (Syntax 8.5). Canonical expression form so the editor can reopen the binding.
  • Loops: IDs inside get per-item suffixes on the page; keep ID references inside the item; JavaScript finds looped elements by class or data-* (Dynamic data 5.5).
  • Islands: decide the form by wp jikji blocks list's attrsOnly (Syntax 8.6); never hand-write markup of static blocks (core/paragraph, core/image… are Jikji elements instead); only j:if on an island; wp jikji content import to move block-editor content.
  • Styles: ID rows by default, every row of the document on every save; new classes with a prefix (agc-btn); an existing class — read it first (wp jikji styles list), send no row to only use it, send baseCss or --update-classes to change it; --strict-css when porting mock-up CSS (Styles 4.5–4.6).

11.4 Recipe A — a page with wp jikji #

BASH
WP="wp --path=/var/www/site"      # runs as the default administrator; add --user=<login> to restrict

# 1. The WordPress page (draft until the document is ready)
PAGE=$($WP post create --post_type=page --post_title='Agent CLI Landing' --porcelain)

# 2. Markup and styles with {name} placeholders — the server issues the ids
cat > page.html <<'HTML'
<section id="{hero}" class="agc-hero">
  <div id="{inner}">
    <h1 id="{title}" j:text="jikji_post('title', $post)">Page title</h1>
    <p id="{lead}">Built by an AI coding agent with wp jikji.</p>
    <a id="{cta}" class="agc-btn" href="#{list}">Latest posts</a>
  </div>
</section>
<section id="{list}">
  <ul id="{loop}" j:each="jikji_query('{&quot;post_type&quot;:&quot;post&quot;,&quot;posts_per_page&quot;:3}', $post) as $item">
    <li id="{item}"><a id="{item_link}" href="#" j:attr:href="jikji_post('permalink', $item)" j:text="jikji_post('title', $item)">Post title</a></li>
  </ul>
</section>
HTML
cat > styles.json <<'JSON'
[
  {"name": "{hero}", "type": "I", "css": "padding:96px 24px;background:#f5f3ff;@media (max-width: --jikji-bp-mobile-portrait){padding:48px 16px;}"},
  {"name": "{inner}", "type": "I", "css": "max-width:960px;margin:0 auto;"},
  {"name": "{title}", "type": "I", "css": "font-size:48px;line-height:1.1;@media (max-width: --jikji-bp-tablet){font-size:36px;}"},
  {"name": "agc-btn", "type": "C", "css": "display:inline-block;padding:12px 22px;border-radius:6px;background:#5b3df5;color:#ffffff;text-decoration:none;"}
]
JSON

# 3. Check, save (a draft: not compiled yet), check the bindings
$WP jikji content validate --html=page.html --styles=styles.json --placeholders
$WP jikji content save "$PAGE" --html=page.html --styles=styles.json --placeholders --format=json > saved.json
$WP jikji eval "$PAGE" "jikji_post('title', \$post)"

# 4. Publish (core command: save_post compiles) and confirm
$WP post update "$PAGE" --post_status=publish
$WP jikji status "$PAGE" --format=json > status.json
jq -e '.compileError == "" and .status == "publish"' status.json
curl -sS "$(jq -r .url status.json)" | grep -o "<h1 id=\"$(jq -r .placeholders.title saved.json)\">[^<]*</h1>"
  • saved.json's placeholders is the mapping ({hero: "jk-…", …}). Later edits start from wp jikji content get "$PAGE" --field=html > page.html.
  • If agc-btn already exists the save fails with jikji_class_exists: drop the row to only use the class, or --update-classes to change it.
  • For an existing page use its ID in step 1; if it is already published, the save in step 3 is the publish (compiled: true).

11.5 Recipe B — pages and templates over REST#

The REST versions of this and of the template recipe are in REST API 10.7–10.8; the wp jikji version of the template recipe is below.

Recipe C — a template and a part with wp jikji #

The flow is prepare the template post → adopt (Jikji manages it; a Jikji draft) → save → verify → publish. Which template to make, and the create/adopt/prepare rules, are in Templates 6.5.

BASH
# 1. A custom template (its blocks stay as the fallback), Jikji-managed, used by the page
$WP jikji template create agent-cli-landing --title='Agent CLI Landing' --assign="$PAGE" --format=json > tpl.json
TPL=$(jq -r .wpId tpl.json)

# 2. A new part: create, save, publish (a new part only renders where it is included)
$WP jikji part create --title='Agent CLI Banner' --format=json > part.json
PART=$(jq -r .wpId part.json); PART_SLUG=$(jq -r .slug part.json)
cat > part.html <<'HTML'
<div id="{banner}"><a id="{home}" href="#" j:attr:href="jikji_site('url')" j:text="jikji_site('name')">Site</a> · Free shipping this week</div>
HTML
echo '[{"name": "{banner}", "type": "I", "css": "padding:10px 24px;background:#111827;color:#ffffff;text-align:center;"}]' > part-styles.json
$WP jikji content save "$PART" --html=part.html --styles=part-styles.json --placeholders
$WP jikji template publish "$PART"

# 3. The template document: theme header/footer, the new part, the page's title and body
cat > template.html <<HTML
<div j:part="header"></div>
<div j:part="$PART_SLUG"></div>
<main id="{main}"><h1 id="{title}" j:text="jikji_post('title', \$post)">Title</h1><div id="{body}" j:html="jikji_post('content', \$post)"></div></main>
<div j:part="footer"></div>
HTML
echo '[{"name": "{main}", "type": "I", "css": "max-width:880px;margin:0 auto;padding:48px 24px;"}]' > tpl-styles.json
$WP jikji content save "$TPL" --html=template.html --styles=tpl-styles.json --placeholders

# 4. Check the bindings under the template's sample (the page), then publish
$WP jikji template sample "$TPL" --vars="{\"page_id\": $PAGE}"
cat > checks.json <<'JSON'
[
  {"key": "title", "expr": "jikji_post('title', $post)", "mode": "text", "scope": []},
  {"key": "site",  "expr": "jikji_site('name')", "mode": "text", "scope": []}
]
JSON
$WP jikji eval "$TPL" --items=checks.json
$WP jikji template publish "$TPL"
$WP jikji status "$TPL" --format=json | jq -c '{status, compileError, runtimeError, siteWide}'
  • template create refuses hierarchy names (jikji_hierarchy_slug); hierarchy templates start with wp jikji template adopt <slug> (or prepare when the theme lacks them) and their publish/unpublish need --yes.
  • template create checks what it can before writing; a later failure reports jikji_partial_failure with data.resume, the command to continue with (adopt and assign are idempotent).
  • Adopting a theme part (template adopt header --part) and publishing it changes every page that uses the part.
  • A synced pattern: wp jikji pattern adopt <id>, then template publish <id> --yes (Templates 6.4).

11.6 Verifying#

Save responses — wp jikji … --format=json exits 0 with the result or 1 with {code, message, data}; the codes are the REST ones (REST API 10.9).

Before publishing — evaluate bindings. wp jikji eval (= POST /render/data) runs expressions in the document's context (a template's sample query) and returns display values, so typos and empty fields are caught first (Dynamic data 5.10). For templates, change the sample: wp jikji template sample <id> --vars='{"cat": 3}', {"s": "a"}, {"error": "404"}, {"p": 12, "post_type": "post"}.

After publishing.

  • Request the front end and look for the element IDs and texts (curl -sS <url> | grep 'id="jk-…"'); purge or bypass a page cache.
  • wp jikji status <id> --format=json — state, URL, compileError, a template's runtimeError, the live version, siteWide. Over REST: GET /content/<id>'s compileError, GET /templates items' jikji.compileError / jikji.runtimeError.
  • A template runtimeError means visitors see the block fallback — fix and publish again, or wp jikji template unpublish <id> --yes to return at once.
  • wp jikji recompile <id> regenerates the output and reports per document (exit 1 on a failure).
  • Draft previews (?preview=true; templates ?jikji_template_preview=<id>) are for logged-in builders; headless checks of a draft are not possible — publish on a staging site, or hand the preview link to a person.

A mock-up port in order: 1) content validate … --placeholders --strict-css (structure, syntax, no dropped CSS; move the rest to the theme); 2) save as a draft (page draft, template adopted/prepared Jikji draft) — no site impact yet; 3) template sample, eval --items=checks.json; 4) compare the look on the canvas per width and in the draft preview; 5) publish (post update --post_status=publish / template publish … --yes) and check compiled: true, empty compileError/runtimeError; 6) the front end — HTML, 404s, pagination, forms, JS, keyboard. Report what was seen in the editor, what eval showed and what was tested on the front end separately: a successful compile is not a functional test.

11.7 Fixing, undoing, cleaning up#

Task wp jikji REST / scripts
Edit an existing document content get <id> --field=html > page.html, --field=hash for the version → edit → content save <id> --html=page.html --base-hash=<hash> GET /content/<id> → save with baseHash. Send all of the document's ID rows (unsent rows stay)
Undo revisions list <id> → revisions restore <id> <rev> GET /content/<id>/revisions → POST …/restore {"baseHash": …}
Take a page private wp post update <id> --post_status=draft (output files stay; nothing renders) Same. Detaching only the Jikji document from a page is not a feature yet — do not delete the meta
Unpublish a template template unpublish <id> — the site uses the block template POST /templates/<id>/status {"status":"draft"}
Release a template from Jikji template release <id> — Jikji data and output removed, the post and blocks stay DELETE /templates/<id>/jikji
Remove test data wp post delete <id> --force (templates and parts: template release first) Collect the document's ID styles with (new Style_Repository())->get_ids_for_template( $id ), then Template_Repository::purge( $id ) and wp_delete_post( $id, true ) for templates and parts, and finally (new Style_Repository())->delete( $names ) for the test IDs and classes — never a class another document uses. There is no command for style rows

11.8 Do not#

  • Write Jikji meta (_jikji_content, _jikji_template_status…) with update_post_meta — it skips validation, syntax checks, style mapping, revisions and compiling.
  • Edit or delete the PHP/CSS files under wp-content/jikji/ — the next publish overwrites them, and a broken pointer makes the front end fall back.
  • Change the {prefix}jikji_styles / {prefix}jikji_template_style tables with SQL.
  • Reuse a readable fixed ID across documents (one shared style row).
  • Resend an existing class without baseCss (a global overwrite).
  • Publish a hierarchy template (index, single, the theme header) without confirmation — the whole site changes. On jikji_confirmation_required, ask a person; do not append --yes mechanically.
  • Change security settings (application-password blocking, firewalls).
  • Put user-supplied values into j:html or j:code — they are not escaped.
  • Use attrsOnly: no blocks (core/paragraph, core/image…) as attributes-only islands or invent their markup — empty output or a refused save; write such content as Jikji elements.
  • Put j: attributes or Jikji elements inside an island — they are just strings. Condition with the island's j:if, repeat with an outer j:each.
  • Call POST /jikji/v1/ai/turn as a model proxy, or change the site's AI settings (Connectors keys, Appearance → Jikji → AI).

11.9 wp eval-file scripts#

When a behaviour has no command, call the plugin classes; the save, validation and compile path is the same.

Class / function Use
Jikji\Settings::is_post_type_enabled( $type ), Settings::all() Enabled post types, icon sets, breakpoints
Jikji\Id_Generator::generate( $n ) n collision-checked IDs (1–50)
Jikji\Render\Content_Service::version( $id ) The document version (lock token)
Jikji\Render\Content_Service::save( $id, $html, $styles, array( 'base_hash' => … ) ) Save (validation, SVG sanitizing, syntax check, mapping, revision; compile when published). WP_Error on failure
Jikji\Render\Compile_Service::last_error( $id ) The last compile failure ('' when none)
Jikji\Storage\Style_Repository — get_all_classes(), get_ids_for_template( $id ) Existing classes; a document's ID styles
Jikji\Templates\Template_Support::is_block_theme() Whether templates are available
Jikji\Templates\Template_Repository — all(), adopt( '<theme>//<slug>', 'wp_template'\|'wp_template_part', $import ), adopt_pattern( $id, $import ), create_part( $title, $slug, $area ), set_status( $id, 'publish'\|'draft' ), release( $id ) Templates list, adoption, new parts, publish state, release
Jikji\Templates\Sample_Query::set( $id, $vars ) A template's editing sample
Jikji\Templates\Runtime_Errors::get( $id ) A template's recorded runtime error

A page (wp --path=<wordpress> eval-file page.php):

PHP
<?php
use Jikji\Id_Generator;
use Jikji\Render\Compile_Service;
use Jikji\Render\Content_Service;
use Jikji\Settings;
use Jikji\Storage\Style_Repository;

wp_set_current_user( 1 ); // An administrator: jikji_compile + edit_post.

if ( ! Settings::is_post_type_enabled( 'page' ) ) {
    WP_CLI::error( 'Jikji is not enabled for pages (Appearance → Jikji → General → Post types).' );
}

// 1. The WordPress page (draft until the document is ready).
$page_id = wp_insert_post( array( 'post_type' => 'page', 'post_status' => 'draft', 'post_title' => 'Agent Guide Landing' ), true );
if ( is_wp_error( $page_id ) ) {
    WP_CLI::error( $page_id->get_error_message() );
}

// 2. Markup with placeholder ids, then real ids from the server pool.
$html = <<<'HTML'
<section id="{hero}" class="agl-hero">
  <div id="{inner}">
    <h1 id="{title}" j:text="jikji_post('title', $post)">Page title</h1>
    <p id="{lead}">Built by an AI coding agent through Jikji.</p>
    <a id="{cta}" class="agl-btn" href="/contact/">Contact us</a>
  </div>
</section>
<section id="{list}">
  <h2 id="{list_title}">Latest posts</h2>
  <ul id="{loop}" j:each="jikji_query('{&quot;post_type&quot;:&quot;post&quot;,&quot;posts_per_page&quot;:3}', $post) as $item">
    <li id="{item}"><a id="{item_link}" href="#" j:attr:href="jikji_post('permalink', $item)" j:text="jikji_post('title', $item)">Post title</a></li>
  </ul>
</section>
HTML;
preg_match_all( '/\{([a-z_]+)\}/', $html, $m );
$keys = array_values( array_unique( $m[1] ) );
$ids  = array_combine( $keys, Id_Generator::generate( count( $keys ) ) );
$html = strtr( $html, array_combine( array_map( static function ( $k ) { return '{' . $k . '}'; }, $keys ), array_values( $ids ) ) );

// 3. Style rows: id styles for this page; a class only if it is new.
$classes = array();
foreach ( ( new Style_Repository() )->get_all_classes() as $row ) {
    $classes[ $row['name'] ] = $row['css'];
}
$styles = array(
    array( 'name' => $ids['hero'], 'type' => 'I', 'css' => 'padding:96px 24px;background:#f5f3ff;@media (max-width: --jikji-bp-mobile-portrait){padding:48px 16px;}' ),
    array( 'name' => $ids['inner'], 'type' => 'I', 'css' => 'max-width:960px;margin:0 auto;' ),
    array( 'name' => $ids['title'], 'type' => 'I', 'css' => 'font-size:48px;line-height:1.1;@media (max-width: --jikji-bp-tablet){font-size:36px;}' ),
    array( 'name' => $ids['list'], 'type' => 'I', 'css' => 'max-width:960px;margin:48px auto;padding:0 24px;' ),
);
if ( ! isset( $classes['agl-btn'] ) ) {
    $styles[] = array( 'name' => 'agl-btn', 'type' => 'C', 'css' => 'display:inline-block;padding:12px 22px;border-radius:6px;background:#5b3df5;color:#ffffff;text-decoration:none;', 'baseCss' => '' );
}

// 4. Save (validated, syntax-checked, SVG-sanitized, mapped, revisioned).
$saved = Content_Service::save( $page_id, $html, $styles, array( 'base_hash' => Content_Service::version( $page_id ) ) );
if ( is_wp_error( $saved ) ) {
    WP_CLI::error( $saved->get_error_message() . ' ' . wp_json_encode( $saved->get_error_data() ) );
}

// 5. Publish: save_post compiles the PHP template and CSS.
wp_update_post( array( 'ID' => $page_id, 'post_status' => 'publish' ) );
$error = Compile_Service::last_error( $page_id );
if ( '' !== $error ) {
    WP_CLI::error( "Published, but the compile failed: $error" );
}
WP_CLI::success( sprintf( 'Page %d published: %s', $page_id, get_permalink( $page_id ) ) );

A template and a part (wp eval-file template.php <page_id>):

PHP
<?php
use Jikji\Id_Generator;
use Jikji\Render\Content_Service;
use Jikji\Templates\Sample_Query;
use Jikji\Templates\Template_Repository;
use Jikji\Templates\Template_Support;

wp_set_current_user( 1 ); // jikji_compile + edit_theme_options.
if ( ! Template_Support::is_block_theme() ) {
    WP_CLI::error( 'Jikji templates need a block theme.' );
}
$page_id = (int) ( $args[0] ?? 0 );
$slug    = 'agent-cli-landing';

/** Replace {name} placeholders with ids from the server pool. */
$with_ids = static function ( $html ) {
    preg_match_all( '/\{([a-z_]+)\}/', $html, $m );
    $keys = array_values( array_unique( $m[1] ) );
    if ( ! $keys ) {
        return array( $html, array() );
    }
    $ids = array_combine( $keys, Id_Generator::generate( count( $keys ) ) );
    $map = array();
    foreach ( $ids as $key => $id ) {
        $map[ '{' . $key . '}' ] = $id;
    }
    return array( strtr( $html, $map ), $ids );
};
$save = static function ( $wp_id, $html, array $styles ) {
    $r = Content_Service::save( $wp_id, $html, $styles, array( 'base_hash' => Content_Service::version( $wp_id ) ) );
    if ( is_wp_error( $r ) ) {
        WP_CLI::error( $r->get_error_message() . ' ' . wp_json_encode( $r->get_error_data() ) );
    }
};
$publish = static function ( $wp_id ) {
    $r = Template_Repository::set_status( $wp_id, 'publish' );
    if ( is_wp_error( $r ) ) {
        WP_CLI::error( 'Publish failed: ' . $r->get_error_message() );
    }
};

// 1. A custom template post (core REST, in-process); its blocks are the fallback.
$req = new WP_REST_Request( 'POST', '/wp/v2/templates' );
$req->set_param( 'slug', $slug );
$req->set_param( 'title', 'Agent CLI Landing' );
$req->set_param( 'content', '<!-- wp:post-content /-->' );
$res = rest_do_request( $req );
if ( $res->is_error() ) {
    WP_CLI::error( $res->as_error()->get_error_message() );
}

// 2. Manage it with Jikji (skeleton content, Jikji draft).
$tpl = Template_Repository::adopt( get_stylesheet() . '//' . $slug, 'wp_template' );
if ( is_wp_error( $tpl ) ) {
    WP_CLI::error( $tpl->get_error_message() );
}

// 3. A new part, saved and published.
$part = Template_Repository::create_part( 'Agent CLI Banner', '', 'uncategorized' );
if ( is_wp_error( $part ) ) {
    WP_CLI::error( $part->get_error_message() );
}
list( $part_html, $pid ) = $with_ids( '<div id="{banner}"><p id="{text}">Free shipping this week.</p></div>' );
$save( $part['wpId'], $part_html, array( array( 'name' => $pid['banner'], 'type' => 'I', 'css' => 'padding:10px 24px;background:#111827;color:#ffffff;text-align:center;' ) ) );
$publish( $part['wpId'] );

// 4. The template document.
list( $html, $ids ) = $with_ids(
    '<div j:part="header"></div>'
    . '<div j:part="' . $part['slug'] . '"></div>'
    . '<main id="{main}"><h1 id="{title}" j:text="jikji_post(\'title\', $post)">Title</h1>'
    . '<div id="{content}" j:html="jikji_post(\'content\', $post)"></div></main>'
    . '<div j:part="footer"></div>'
);
$save( $tpl['wpId'], $html, array( array( 'name' => $ids['main'], 'type' => 'I', 'css' => 'max-width:880px;margin:0 auto;padding:48px 24px;' ) ) );

// 5. The editor's sample (optional): edit it as the page it is meant for.
if ( $page_id ) {
    Sample_Query::set( $tpl['wpId'], array( 'page_id' => $page_id ) );
}

// 6. Publish, then use it for the page.
$publish( $tpl['wpId'] );
if ( $page_id ) {
    update_post_meta( $page_id, '_wp_page_template', $slug );
}
WP_CLI::success( sprintf( 'Template %d and part %d (%s) published%s.', $tpl['wpId'], $part['wpId'], $part['slug'], $page_id ? ' for ' . get_permalink( $page_id ) : '' ) );

Chapters