wp_change_slug
Rename a URL slug with preview and verification, warning if the old URL will break for pages. Supports dry-run to test before applying.
Instructions
Rename one page/post's URL slug (the old URL usually starts 404ing - read on).
CHECK old_url_redirects IN THE RESULT. WordPress only 301s the old URL for
published POSTS; for PAGES (hierarchical, and what most site URLs are) it does not,
so the old URL 404s until a redirect is added elsewhere. Both the preview and the
result say which case this is, with a warning when the old URL will break.
post_id comes from wp_find_page / wp_get_content. new_slug is sanitized to
WP-safe form (lowercase, a-z 0-9 and hyphens; anything else becomes a hyphen) - a
value with nothing usable left is refused rather than sent. If the slug is already
taken, WP stores a uniquified one (about -> about-2): that still succeeds and comes
back with uniquified: true and the ACTUAL slug, so check it. DEFAULTS TO
dry_run=true (returns a preview with the current slug; writes nothing). Pass
dry_run=false to apply - the rename is verified by reading the post back. Requires
the REST transport. Prod writes require allow_prod=true.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dry_run | No | ||
| install | Yes | ||
| post_id | Yes | ||
| new_slug | Yes | ||
| allow_prod | No |